diff --git a/core/Cargo.toml b/core/Cargo.toml index dbc59e64e..c9390dc38 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -16,5 +16,5 @@ repository = "Enet4/dicom-rs" [dependencies] chrono = "0.4.6" itertools = "0.8.0" -quick-error = "1.2.2" +quick-error = "1.2.3" smallvec = "1.0.0" diff --git a/core/src/error.rs b/core/src/error.rs index 77b59f470..760d493b9 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -2,7 +2,6 @@ use crate::value::ValueType; use crate::Tag; use quick_error::quick_error; -use std::error::Error as BaseError; use std::fmt; use std::num::{ParseFloatError, ParseIntError}; use std::result; @@ -13,26 +12,21 @@ quick_error! { pub enum Error { /// Raised when the obtained data element was not the one expected. UnexpectedTag(tag: Tag) { - description("Unexpected DICOM element tag in current reading position") display("Unexpected DICOM tag {}", tag) } /// Raised when the obtained length is inconsistent. UnexpectedDataValueLength { - description("Inconsistent data value length in data element") + display("Inconsistent data value length in data element") } /// Error related to an invalid value read. ReadValue(err: InvalidValueReadError) { - description("Invalid value read") + display("Invalid value read: {}", err) from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) } /// A failed attempt to cast a value to an inappropriate format. CastValue(err: CastValueError) { - description("Failed value cast") + display("Failed value cast: {}", err) from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) } } } @@ -47,59 +41,46 @@ quick_error! { pub enum InvalidValueReadError { /// The value cannot be read as a primitive value. NonPrimitiveType { - description("attempted to retrieve complex value as primitive") - display(self_) -> ("{}", self_.description()) + display("attempted to retrieve complex value as primitive") } /// The value's effective length cannot be resolved. UnresolvedValueLength { - description("value length could not be resolved") - display(self_) -> ("{}", self_.description()) + display("value length could not be resolved") } /// The value does not have the expected format. InvalidToken(got: u8, expected: &'static str) { - description("Invalid token received for the expected value representation") - display(self_) -> ("invalid token: expected {} but got {:?}", expected, got) + display("invalid token: expected {} but got {:?}", expected, got) } /// The value does not have the expected length. InvalidLength(got: usize, expected: &'static str) { - description("Invalid slice length for the expected value representation") - display(self_) -> ("invalid length: expected {} but got {}", expected, got) + display("invalid length: expected {} but got {}", expected, got) } /// Invalid date or time component. ParseDateTime(got: u32, expected: &'static str) { - description("Invalid date/time component") - display(self_) -> ("invalid date/time component: expected {} but got {}", expected, got) + display("invalid date/time component: expected {} but got {}", expected, got) } /// Invalid or ambiguous combination of date with time. DateTimeZone { - description("Invalid or ambiguous combination of date with time") - display(self_) -> ("{}", self_.description()) + display("Invalid or ambiguous combination of date with time") } /// chrono error when parsing a date or time. Chrono(err: chrono::ParseError) { - description("failed to parse date/time") + display("failed to parse date/time: {}", err) from() - cause(err) - display(self_) -> ("{}", self_.source().unwrap()) } /// The value cannot be parsed to a floating point number. ParseFloat(err: ParseFloatError) { - description("Failed to parse text value as a floating point number") + display("Failed to parse text value as a floating point number") from() - cause(err) - display(self_) -> ("{}", self_.description()) } /// The value cannot be parsed to an integer. ParseInteger(err: ParseIntError) { - description("Failed to parse text value as an integer") + display("Failed to parse text value as an integer") from() - cause(err) - display(self_) -> ("{}", err.description()) } /// An attempt of reading more than the number of bytes in the length attribute was made. UnexpectedEndOfElement { - description("Unexpected end of element") - display(self_) -> ("{}", self_.description()) + display("Unexpected end of element") } } } @@ -118,16 +99,10 @@ impl fmt::Display for CastValueError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{}: requested {} but value is {:?}", - self.description(), - self.requested, - self.got + "bad value cast: requested {} but value is {:?}", + self.requested, self.got ) } } -impl ::std::error::Error for CastValueError { - fn description(&self) -> &str { - "bad value cast" - } -} +impl ::std::error::Error for CastValueError {} diff --git a/encoding/Cargo.toml b/encoding/Cargo.toml index 9230c709e..ed576403f 100644 --- a/encoding/Cargo.toml +++ b/encoding/Cargo.toml @@ -16,7 +16,7 @@ inventory-registry = ['inventory'] [dependencies] dicom-core = { path = "../core", version = "0.1.0" } dicom-dictionary-std = { path = "../dictionary-std", version = "0.1.0" } -quick-error = "1.2.2" +quick-error = "1.2.3" encoding = "0.2.33" byteordered = "0.5.0" inventory = { version = "0.1.4", optional = true } diff --git a/encoding/src/error.rs b/encoding/src/error.rs index d77d10075..21191405e 100644 --- a/encoding/src/error.rs +++ b/encoding/src/error.rs @@ -3,7 +3,6 @@ pub use dicom_core::error::{CastValueError, InvalidValueReadError}; use dicom_core::Tag; use quick_error::quick_error; use std::borrow::Cow; -use std::error::Error as BaseError; use std::fmt; use std::io; @@ -16,40 +15,31 @@ quick_error! { pub enum Error { /// Raised when the obtained data element tag was not the one expected. UnexpectedTag(tag: Tag) { - description("Unexpected DICOM element tag in current reading position") display("Unexpected DICOM tag {}", tag) } /// Raised when the obtained length is inconsistent. UnexpectedDataValueLength { - description("Inconsistent data value length in data element") + display("Inconsistent data value length in data element") } /// Error related to an invalid value read. ReadValue(err: InvalidValueReadError) { - description("Invalid value read") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("Invalid value read: {}", err) } /// Error related to a failed text encoding / decoding procedure. TextEncoding(err: TextEncodingError) { - description("Failed text encoding/decoding") + display("Failed text encoding/decoding: {}", err) from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) } /// A failed attempt to cast a value to an inappropriate format. CastValue(err: CastValueError) { - description("Failed value cast") + display("Failed value cast: {}", err) from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) } /// Other I/O errors. Io(err: io::Error) { - description("I/O error") + display("I/O error: {}", err) from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) } } } @@ -79,12 +69,8 @@ impl TextEncodingError { impl fmt::Display for TextEncodingError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}: {}", self.description(), self.0) + write!(f, "encoding/decoding process failed: {}", self.0) } } -impl ::std::error::Error for TextEncodingError { - fn description(&self) -> &str { - "encoding/decoding process failed" - } -} +impl ::std::error::Error for TextEncodingError {} diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 05c4d4f4d..22e48a59e 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/Enet4/dicom-rs" [dependencies] dicom-core = { path = "../core", version = "0.1.0" } dicom-encoding = { path = "../encoding", version = "0.1.0" } -quick-error = "1.2.2" +quick-error = "1.2.3" chrono = "0.4.6" dicom-dictionary-std = { path = "../dictionary-std/", version = "0.1.0" } smallvec = "1.0.0" diff --git a/parser/src/error.rs b/parser/src/error.rs index 0818e10f9..d381911d0 100644 --- a/parser/src/error.rs +++ b/parser/src/error.rs @@ -4,7 +4,6 @@ pub use dicom_core::error::{CastValueError, InvalidValueReadError}; use dicom_core::Tag; use dicom_encoding::error::{Error as EncodingError, TextEncodingError}; use quick_error::quick_error; -use std::error::Error as BaseError; use std::fmt; use std::io; @@ -17,7 +16,7 @@ quick_error! { pub enum Error { /// Not valid DICOM content, typically raised when checking the magic code. InvalidFormat { - description("Content is not DICOM or is corrupted") + display("Content is not DICOM or is corrupted") } /// A required element in the meta group is missing MissingMetaElement(name: &'static str) { @@ -25,81 +24,69 @@ quick_error! { } /// Raised when the obtained data element was not the one expected. UnexpectedTag(tag: Tag) { - description("Unexpected DICOM element tag in current reading position") display("Unexpected DICOM tag {}", tag) } InconsistentSequenceEnd(eos: u64, bytes_read: u64) { - description("inconsistence sequence end position") display("already read {} bytes, but end of sequence is @ {} bytes", bytes_read, eos) } /// Raised when the obtained length is inconsistent. UnexpectedDataValueLength { - description("Inconsistent data value length in data element") + display("Inconsistent data value length in data element") } /// Raised when a read was illegally attempted. IllegalDataRead { - description("Illegal data value read") + display("Illegal data value read") } /// Raised when the demanded transfer syntax is not supported. UnsupportedTransferSyntax { - description("Unsupported transfer syntax") + display("Unsupported transfer syntax") } /// Raised when the required character set is not supported. UnsupportedCharacterSet { - description("Unsupported character set") + display("Unsupported character set") } /// Raised when attempting to fetch an element by an unknown attribute name. NoSuchAttributeName { - description("No such attribute name") + display("No such attribute name") } /// Raised when attempting to fetch an unexistent element. NoSuchDataElement { - description("No such data element") + display("No such data element") } /// Raised when attempting to read pixel data out of bounds. PixelDataOutOfBounds { - description("Pixel data access index out of bounds") + display("Pixel data access index out of bounds") } /// Raised when a data set parser couldn't fetch a value after a primitive /// data element's header. MissingElementValue { - description("Expected value after data element header, but was missing") + display("Expected value after data element header, but was missing") } /// Raised while parsing a DICOM data set and found an unexpected /// element header or value. DataSetSyntax(err: DataSetSyntaxError) { - description("Data set syntax error") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("Data set syntax error: {}", err) } /// Error related to an invalid value read. ReadValue(err: InvalidValueReadError) { - description("Invalid value read") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("Invalid value read: {}", err) } /// Error related to a failed text encoding / decoding procedure. TextEncoding(err: TextEncodingError) { - description("Failed text encoding/decoding") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("Failed text encoding/decoding: {}", err) } /// A failed attempt to cast a value to an inappropriate format. CastValue(err: CastValueError) { - description("Failed value cast") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("Failed value cast: {}", err) } /// Other I/O errors. Io(err: io::Error) { - description("I/O error") from() - cause(err) - display(self_) -> ("{}: {}", self_.description(), err.description()) + display("I/O error: {}", err) } } } @@ -137,10 +124,8 @@ pub enum DataSetSyntaxError { impl fmt::Display for DataSetSyntaxError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - DataSetSyntaxError::PrematureEnd => f.write_str(self.description()), - DataSetSyntaxError::UnexpectedToken(ref token) => { - write!(f, "{} {}", self.description(), token) - } + DataSetSyntaxError::PrematureEnd => write!(f, "{}", self), + DataSetSyntaxError::UnexpectedToken(ref token) => write!(f, "{} {}", self, token), } } } diff --git a/scpproxy/Cargo.toml b/scpproxy/Cargo.toml index ecd356644..b02dd6b09 100644 --- a/scpproxy/Cargo.toml +++ b/scpproxy/Cargo.toml @@ -9,6 +9,6 @@ repository = "https://github.com/Enet4/dicom-rs" [dependencies] clap = "2.33.0" -quick-error = "1.2.2" +quick-error = "1.2.3" dicom-ul = { path = "../ul/", version = "0.1.0" } -dicom-dictionary-std = { path = "../dictionary-std/", version = "0.1.0" } \ No newline at end of file +dicom-dictionary-std = { path = "../dictionary-std/", version = "0.1.0" } diff --git a/ul/Cargo.toml b/ul/Cargo.toml index 439f8fbf3..7043a5cbc 100644 --- a/ul/Cargo.toml +++ b/ul/Cargo.toml @@ -8,9 +8,9 @@ license = "MIT/Apache-2.0" repository = "https://github.com/Enet4/dicom-rs" [dependencies] -quick-error = "1.2.2" +quick-error = "1.2.3" byteordered = "0.5.0" dicom-encoding = { path = "../encoding/", version = "0.1.0" } [dev-dependencies] -matches = "0.1.8" \ No newline at end of file +matches = "0.1.8" diff --git a/ul/src/error.rs b/ul/src/error.rs index ef4f84ea4..8e7759b6b 100644 --- a/ul/src/error.rs +++ b/ul/src/error.rs @@ -1,5 +1,4 @@ use quick_error::quick_error; -use std::error::Error as BaseError; /// Type alias for a result from this crate. pub type Result = std::result::Result; @@ -9,64 +8,50 @@ quick_error! { pub enum Error { Io(err: std::io::Error) { from() - display(self_) -> ("io error: {}", err) + display("io error: {}", err) } NoPduAvailable { - description("no pdu was available") - display(self_) -> ("{}", self_.description()) + display("no pdu was available") } InvalidMaxPdu { - description("invalid max pdu") - display(self_) -> ("{}", self_.description()) + display("invalid max pdu") } PduTooLarge { - description("the incoming pdu was too large") - display(self_) -> ("{}", self_.description()) + display("the incoming pdu was too large") } InvalidPduVariable { - description("the pdu contained an invalid value") - display(self_) -> ("{}", self_.description()) + display("the pdu contained an invalid value") } MultipleTransferSyntaxesAccepted { - description("multiple transfer syntaxes were accepted") - display(self_) -> ("{}", self_.description()) + display("multiple transfer syntaxes were accepted") } InvalidRejectSourceOrReason { - description("the reject source or reason was invalid") - display(self_) -> ("{}", self_.description()) + display("the reject source or reason was invalid") } InvalidAbortSourceOrReason { - description("the abort service provider reason was invalid") - display(self_) -> ("{}", self_.description()) + display("the abort service provider reason was invalid") } InvalidPresentationContextResultReason { - description("the presentation context result reason was invalid") - display(self_) -> ("{}", self_.description()) + display("the presentation context result reason was invalid") } InvalidTransferSyntaxSubItem { - description("invalid transfer syntax sub-item") - display(self_) -> ("{}", self_.description()) + display("invalid transfer syntax sub-item") } UnknownPresentationContextSubItem { - description("unknown presentation context sub-item") - display(self_) -> ("{}", self_.description()) + display("unknown presentation context sub-item") } EncodingError(err: dicom_encoding::error::Error) { from() - description("encoding error") - display(self_) -> ("{} {}", err, self_.description()) + display("{} encoding error", err) } MissingApplicationContextName { - description("missing application context name") - display(self_) -> ("{}", self_.description()) + display("missing application context name") } MissingAbstractSyntax { - description("missing abstract syntax") - display(self_) -> ("{}", self_.description()) + display("missing abstract syntax") } MissingTransferSyntax { - description("missing transfer syntax") - display(self_) -> ("{}", self_.description()) + display("missing transfer syntax") } } }