suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

Descriptive error messages for invalid tags in the dataset #123

Open suever opened 9 years ago

suever commented 9 years ago

From videa...@gmail.com on March 29, 2013 15:24:07

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:

Attachment: ex_fail.py tag_in_exception.patch

Original issue: http://code.google.com/p/pydicom/issues/detail?id=123

suever commented 9 years ago

From darcymason@gmail.com on April 02, 2013 18:44:04

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

Status: Accepted
Owner: darcymason@gmail.com