google-code-export / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

Descriptive error messages for invalid tags in the dataset #123

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Pydicom correctly throws errors when a tag is of invalid type/value, however it 
is nearly impossible to determine *which* tag is responsible for the offending 
error message.

To reproduce
1. Load/create a dicom dataset
2. Write an incorrect type or value to a dicom tag, say an int where you meant 
to write a string
3. Save the file (error with an unhelpful traceback)

Similarly:
1. Load a dataset with an invalid tag (anything that tickles DateElem.value 
will do)
2. Call Dataset.walk (error with an unhelpful traceback)

What is the expected output? What do you see instead?
Pydicom correctly throws an exception when you make that call, but the high 
level methods (walk, save_as, etc) boot you out at the top of the stack, so 
it's difficult to see where the offender is (in my files it's usually deep in a 
nested sequence... eww).

It would be nice if the traceback was annotated with the failed tag number as 
the value is passed up the stack.  I wrote an 8-line patch to fix that 
(attached), although I'm sure there's a better way.

What version of the product are you using?

Pydicom 0.9.7, 0.9.8, trunk

Attached:

- ex_fail.py - Toy example that reproduces the problem
- tag_in_exception.patch - 8 line context manager to solve the problem in 
Dataset.walk/Dataset.save_as/Dataset.__str__.  I'm sure it could help elsewhere 
too.

Original issue reported on code.google.com by videa...@gmail.com on 29 Mar 2013 at 7:24

Attachments:

GoogleCodeExporter commented 9 years ago
Yes, this is a good point -- pydicom should be more helpful in localizing a bad 
value. I'll have a look at your patch.

Original comment by darcymason@gmail.com on 3 Apr 2013 at 1:44

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 03d4ee111dfa.

Original comment by Suever@gmail.com on 22 Nov 2014 at 5:10