Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot control/except processing tag error in latest version #1909

Open
joon612 opened this issue Oct 16, 2023 · 6 comments
Open

Cannot control/except processing tag error in latest version #1909

joon612 opened this issue Oct 16, 2023 · 6 comments

Comments

@joon612
Copy link

joon612 commented Oct 16, 2023

Describe the bug
When I was working with a large number of dcm files, some of the elements in the dcm didn't conform to the specification (which was out of my control), and then when my script ran, it would generate a lot of error logs.
image

Expected behavior
I feel like I should be able to catch exceptions or control logs.

Steps To Reproduce

    metadata_dict = {}
    try:
        metadata_dict.update(dcm.file_meta.to_json_dict(suppress_invalid_tags=True))
        metadata_dict.update(dcm.to_json_dict(suppress_invalid_tags=True))
    except ValueError as e:
        logging.error(f"Error occurred at tag: {e.args[0]} file: {metadata_file}")
    except Exception as e:
        logging.error(f"{e}: {metadata_file}")

Your environment

$  python3.9 -m pydicom.env_info
module       | version
------       | -------
platform     | Linux-5.15.0-1049-azure-x86_64-with-glibc2.31
Python       | 3.9.18 (main, Aug 25 2023, 13:20:04)  [GCC 9.4.0]
pydicom      | 2.4.2
gdcm         | _module not found_
jpeg_ls      | _module not found_
numpy        | 1.26.0
PIL          | 10.1.0
pylibjpeg    | 1.4.0
openjpeg     | _module not found_
libjpeg      | 1.3.4
@mrbean-bremen
Copy link
Member

You already suppress exceptions by setting suppress_invalid_tags=True, and the invalid tags are just ignored.
What you can't suppress currently is the error logging - I guess the issue is about that?

@joon612
Copy link
Author

joon612 commented Oct 16, 2023

You already suppress exceptions by setting suppress_invalid_tags=True, and the invalid tags are just ignored. What you can't suppress currently is the error logging - I guess the issue is about that?

Indeed.

@mrbean-bremen
Copy link
Member

What I would have expected in this case (e.g. if suppress_invalid_tags=True) would be a warning, not an error.
But I guess you want to have that logging configured away completely, right?

@joon612
Copy link
Author

joon612 commented Oct 17, 2023

What I would have expected in this case (e.g. if suppress_invalid_tags=True) would be a warning, not an error. But I guess you want to have that logging configured away completely, right?

In fact, there are two parts, one is that the error is too concise, I actually do not know the specific reason for the element is not compliant, the other is that I can't control the log, in the past, this kind of is used as a warning, although I can't control them at that time, second, I actually care more about whether it is exported, if it can be exported or processed, it can not be displayed as a warning, if it (element) can not be exported, export the reason.

@mrbean-bremen
Copy link
Member

I actually care more about whether it is exported, if it can be exported or processed, it can not be displayed as a warning, if it (element) can not be exported, export the reason.

I guess by "export the reason" you mean log it?
Currently, the error means that an exception has happened during processing, so the tag will not be exported. It makes indeed sense to at least log the original exception in this case instead of the generic one.

@joon612
Copy link
Author

joon612 commented Oct 17, 2023

I guess by "export the reason" you mean log it?
Yes and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants