Skip to content

Conversation

@Enet4
Copy link
Owner

@Enet4 Enet4 commented Aug 21, 2020

Resolves #36.

This PR replaces all existing quick-error types and redesigns them with the use of snafu. Errors are no longer necessarily crate-level, in many cases they are scoped to a major module (one for encoding::decode, one for encoding::encode, one for object::meta, etc). This also led to an improved context being passed into the errors, such as the reading/writing position of the stateful encoder/decoder.

To serve as an example, these changes turn this error message:

Invalid value read: value length could not be resolved

into this message, plus backtrace:

Could not read data set token: Could not read item value: Undefined value length of element tagged (5533,5533) at position 3548

Pending concerns:

  • refactor errors in the dicom_core crate
  • evaluate whether more backtraces should be optional: in end applications such as dcmdump, the current error definitions and Cargo features will make it so that backtraces are nearly always generated. On the other hand, the guide suggests the use of Option<Backtrace> for errors which may take part in control flow.
  • whether to export opaque error types instead of fully public error types

CC @shepmaster Your feedback on the use of SNAFU has so far has been highly appreciated. 🙏

Enet4 added 11 commits August 21, 2020 15:59
- one crate root error
- one meta module error
- add Cargo features backtraces
- error types for stateful reader, stateful writer,
  data set reader and dataset writer
- improve dicom-object error accordingly
- [encoding] narrow text module result type to Err = TextEncodingError
- use trait OptionExt and selector `.fail()` method
 instead of backtrace generator
- replace root error with module-level snafu errors
- fix writing reserved 43-74 bytes in A-ASSOCIATE-RQ
   - write zeros instead of the character '0'
- statically resolve default text codec
- move pdu write tests to inner tests module
- move the remaining tests to the tests directory
- fmt
- [object] convert experimental pixeldata module to snafu
- error context is on reading a header,
  not a value
- remove quick-error
- remove error module
- at text: EncodeTextError and DecodeTextError
- at encode/decode::basic, error is std::io::Error
- encode-level error + decode-level error types
- [parser] propagate error type differences
- [parser] move DicomElementMarker to an independent module
- [object] propagate error type differences
- [ul] propagate error type differences
- remove recursion_limit attributes

Misc:
- remove missing_docs warn lint
   - very annoying for error types
- refactor transfer syntax impls
   - split encoding and decoding
   - deprecate transfer_syntax specific modules

Fixes:

- add missing check on a write_all
- add #[snafu(backtrace)] attributes
   - otherwise they won't be reachable at top-level
- add more backtraces where appropriate
   - [object] adjust UnsupportedTranserSyntax building
- [encoding] optional backtrace @ decode::Error::ReadHeaderTag
   - since it's also part of the reading logic
- [dcmdump] update error printing routine to benefit from backtraces
- ReadHeaderTag must be applied in the context of header reading,
  otherwise it fails to gracefully detect EOF
Copy link

@shepmaster shepmaster left a comment

Choose a reason for hiding this comment

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

There's a lot of code, so I skimmed ❤️

Enet4 added 9 commits August 21, 2020 22:41
- use std::io
- remove two-step shuffles
- use arrays in encoding tests instead of vectors
- split NoSuchDataElement error variant into two
- update Result type alias to admit inference
- split variant InvalidValueCustom into three
- SequenceItemHeaderError at header module
- remove annoying missing_docs lint
- dictionary: refactor TagRangeParseError
   to no longer be stringly
- Error at value::deserialize
- move CastValueError and ConvertValueError to value::primitive
- [encoding] update decode::Error accordingly
- [parser] update stateful::decode::Error accordingly
will be included as a separate contribution later
- instead rely on error reporters to traverse the error chain
- [dcmdump] update accordingly
- [dcmdump] return -1 on missing arg or --help
- [scpproxy] update accordingly
@Enet4 Enet4 marked this pull request as ready for review August 27, 2020 18:25
Enet4 added 2 commits August 27, 2020 19:35
- [parser] refactor integer comparison into match and .cmp
- [parser] remove .clone() in Copy struct
- [object] redundant field name in struct init
- [dcmdump] redundant import
std::result::Result::Ok to Result::Ok
@Enet4 Enet4 merged commit ee0762f into master Aug 28, 2020
@Enet4 Enet4 deleted the wip/snafu branch August 26, 2021 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error definitions

3 participants