-
Notifications
You must be signed in to change notification settings - Fork 631
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
Handle encoding errors #1200
Comments
the policy with incorrect DICOM is: when generating DICOM data then be as strict as possible, when reading/consuming DICOM data then be as tollerant as possible. error correction in reading DICOM data is a difficult topic. if there are some invalid data but the error is obvious and unambiguous to correct (using spaces or underscores mixed up in values of SpecificCharacterSet), then it is fine, if fo-dicom does this implicit. If there are some other invalid encodings or others, then it is hard to guess the right encoding and fix it. Thats why the default-encoding is used then (ASCII) and replacement characters are used for the unknown characters. In the end this makes it visible to the user that something went wrong with the data. If fo-dicom would somehow guess the encoding and sadly guesses the wrong encoding, the we would generate some wrong data. But logging a warn in this fallback-scenario is a very good idea, of course. |
Yes, that's always a good policy. I think the usage of replacement characters is also what is expected, so what can be added are the respective warnings in the log for invalid encodings, or invalid text for a given encoding. |
I checked how logging is done, and I'm not sure yet what is the correct way to log in a library function. Is there a possibility to use the registered logger(s) for logging, or do we need to pass the logger from the caller (this seems to be done in a few cases)? |
There is the interface |
Thank you, that makes sense! |
yes, it was too much headache for most developers to think about where to get the logger instance from :-) Sure, there are situations where you do not have such a context, for example if you just create a new DicomDataset somewhere in code outside of a DicomClient or DicomServer. |
That sounds like a plan, though the logger would probably have to be added to several methods, which is kind of ugly... I understand that there can be more than one registered logger, therefore it would not be sufficient to just use the registered logger, and there is no concept of a current logger to be used. |
Hm, I'm not sure about the logging yet. The problem is: if I want to pass the logger into the encoding, I have to add it to |
I see. It's not easy. |
Thank you. The event mechanism is certainly a better solution as it avoids passing the logger around too much. I'm not sure yet how the logging would be done in Logging into a default logger does not sound like a good idea, if there already is a logger configured. Before doing anything, I probably first have to understand the current logging system better (I misunderstood this first, as I thought that all loggers are registered in a central instance). I didn't get to it today as I planned, but I will wait anyway for the other PR to be finished before starting a new one to avoid conflicts. |
I may not understand this correctly. If a DicomClient or DicomServer subscribes to the event (that is what you mean by "attach the event", correct?), they have to subscribe to the event source, which would be each DicomElement of the data set - obviously not what you mean. Or do you mean to have a static event? Could you elaborate a bit on this? |
You are absolutely right, my idea went into the wrong direction. Actually I thought of that the DicomClient or DicomServer subscribed the log-event of each Dicomelement. But that would cause a huge amout of issues. so now, after digging into this part of fo-dicom again (it was quite some time ago when I last did this), I see no chance to get some kind of context from DicomClient or Dicomserver into the DicomEncoding class. As long as you do not find any way to manage this, I only can see the possiblility, that the DicomEncoding class holds its own logger instance (getting it from DI-container or creating one directly or however) and log the warnings there. Maybe you could add the current ThreadID into the log entry, then the developer has a chance to detect by ThreadId or Timestamp the context, where the log entry belongs to.... |
Thanks - this is unfortunate. I thought I had missed something. I will probably have another look to understand the logging concept, maybe I can think of something. |
- use log collector for unit tests - see fo-dicom#1200
- use log collector for unit tests - see fo-dicom#1200
* Add error handling for decoding errors - use log collector for unit tests - see #1200 * Findings from review - fix delimiter handling in fragments - do not use a static logger for DicomEncoding - use log collection only for encoding tests * implement fixture in that way that it also runs green if the collections are executed in parallel * fix: registered the serviceprovider on the wrong side of the compiler directive Co-authored-by: Reinhard Gruber <gofal@users.noreply.github.com> Co-authored-by: Reinhard Gruber <r.gruber@smartinmedia.com>
This is a spin-off of PR #1198 and may be done after that is finished.
There are a few cases of incorrect
Specific Character Set
contents that are currently not handled:Somewhat related are decoding errors, e.g. text values that cannot be decoded in the given encoding. Currently, these are silently ignored, and replacement characters are used. We may both issue a warning and use replacement characters here - to be discussed (I'm not sure about the policy with respect to incorrect DICOM in fo-dicom).
The text was updated successfully, but these errors were encountered: