Skip to content

Commit

Permalink
Remove use of deprecated Error::description
Browse files Browse the repository at this point in the history
Error::description is fully deprecated now.
See: rust-lang/rust#66919
  • Loading branch information
robyoung committed May 21, 2020
1 parent 0e016f5 commit 38be8d5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 130 deletions.
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
57 changes: 16 additions & 41 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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())
}
}
}
Expand All @@ -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")
}
}
}
Expand All @@ -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 {}
2 changes: 1 addition & 1 deletion encoding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
28 changes: 7 additions & 21 deletions encoding/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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())
}
}
}
Expand Down Expand Up @@ -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 {}
2 changes: 1 addition & 1 deletion parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
47 changes: 16 additions & 31 deletions parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -17,89 +16,77 @@ 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) {
display("Missing required meta element `{}`", name)
}
/// 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)
}
}
}
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions scpproxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
dicom-dictionary-std = { path = "../dictionary-std/", version = "0.1.0" }
4 changes: 2 additions & 2 deletions ul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
matches = "0.1.8"
Loading

0 comments on commit 38be8d5

Please sign in to comment.