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

[MRG] Add error handling to convert_tag and convert_AE_string #1833

Merged
merged 2 commits into from Jul 7, 2023

Conversation

mrbean-bremen
Copy link
Member

@mrbean-bremen mrbean-bremen commented Jul 6, 2023

  • convert_AE_String handles incorrect value length gracefully
  • convert_tag now raises if the byte_string is too short

These are minor changes related to the previously skipped tests. convert_AE_String had previously warned for incorrect length, but than crashed - it now just ignores extra bytes.
convert_tag is only used in convert_AE_String, but on the chance it is used from outside I raise an exception if the byte string is too short (instead of letting it just crash).

Tasks

  • Unit tests added that reproduce the issue or prove feature is working
  • Fix or feature added
  • Code typed and mypy shows no errors
  • Unit tests passing and overall coverage the same or better

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #1833 (be1dc48) into main (04c7f2e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1833   +/-   ##
=======================================
  Coverage   97.46%   97.47%           
=======================================
  Files          65       65           
  Lines       10851    10854    +3     
=======================================
+ Hits        10576    10580    +4     
+ Misses        275      274    -1     
Impacted Files Coverage Δ
src/pydicom/values.py 98.07% <100.00%> (+0.51%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@mrbean-bremen mrbean-bremen changed the title Add error handling to convert_tag and convert_AE_string [MRG] Add error handling to convert_tag and convert_AE_string Jul 6, 2023
Copy link
Member

@darcymason darcymason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, good to merge if you agree about the raise type and fix that.

fmt = "<HH" if is_little_endian else ">HH"
value = cast(tuple[int, int], unpack(fmt, byte_string[offset : offset + 4]))
value = cast(tuple[int, int], unpack(fmt, byte_string[offset: offset + 4]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be ValueError, because it is a problem with the value, not with it's type. (I suspect I did this in the past too and maybe some need to be corrected)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I was unhappy with TypeError, but for some reason did not think about ValueError. Will fix this tomorrow, I'm done for today...

- convert_AE_String handles incorrect value length gracefully
- convert_tag now raises if the byte_string is too short
@mrbean-bremen mrbean-bremen merged commit 9bb4951 into pydicom:main Jul 7, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants