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

Remove use of deprecated Error::description #41

Merged
merged 3 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
6 changes: 5 additions & 1 deletion core/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::io;
use std::io::{Read, Seek, SeekFrom, Write};
use std::marker::PhantomData;
use std::ops::{DerefMut, Range};
use std::ops::DerefMut;
#[cfg(test)]
use std::ops::Range;

/** A private type trait for the ability to efficiently implement stream skipping.
*/
Expand Down Expand Up @@ -37,6 +39,7 @@ where
S: Seek,
B: DerefMut<Target = S>,
{
#[cfg(test)]
/// Create an interval from the current position and ending
/// after `n` bytes.
pub fn new_here(mut source: B, n: u32) -> io::Result<Self> {
Expand All @@ -50,6 +53,7 @@ where
})
}

#[cfg(test)]
/// Create an interval that starts and ends according to the given
/// range of bytes.
pub fn new_at(mut source: B, range: Range<u64>) -> io::Result<Self> {
Expand Down
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"
8 changes: 4 additions & 4 deletions parser/src/dataset/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ mod tests {
#[rustfmt::skip]
static DATA: &[u8] = &[
0x18, 0x00, 0x11, 0x60, // sequence tag: (0018,6011) SequenceOfUltrasoundRegions
b'S', b'Q', // VR
b'S', b'Q', // VR
0x00, 0x00, // reserved
0x2e, 0x00, 0x00, 0x00, // length: 28 + 18 = 46 (#= 2)
// -- 12 --
Expand All @@ -533,7 +533,7 @@ mod tests {
// -- 48 --
0x18, 0x00, 0x12, 0x60, b'U', b'S', 0x02, 0x00, 0x04, 0x00, // (0018, 6012) RegionSpatialformat, len = 2, value = 4
// -- 58 --
0x20, 0x00, 0x00, 0x40, b'L', b'T', 0x04, 0x00, // (0020,4000) ImageComments, len = 4
0x20, 0x00, 0x00, 0x40, b'L', b'T', 0x04, 0x00, // (0020,4000) ImageComments, len = 4
b'T', b'E', b'S', b'T', // value = "TEST"
];

Expand Down Expand Up @@ -657,7 +657,7 @@ mod tests {
#[rustfmt::skip]
static DATA: &[u8] = &[
0x18, 0x00, 0x11, 0x60, // sequence tag: (0018,6011) SequenceOfUltrasoundRegions
b'S', b'Q', // VR
b'S', b'Q', // VR
0x00, 0x00, // reserved
0xff, 0xff, 0xff, 0xff, // length: undefined
// -- 12 --
Expand All @@ -679,7 +679,7 @@ mod tests {
// -- 74 --
0xfe, 0xff, 0xdd, 0xe0, 0x00, 0x00, 0x00, 0x00, // sequence end
// -- 82 --
0x20, 0x00, 0x00, 0x40, b'L', b'T', 0x04, 0x00, // (0020,4000) ImageComments, len = 4
0x20, 0x00, 0x00, 0x40, b'L', b'T', 0x04, 0x00, // (0020,4000) ImageComments, len = 4
b'T', b'E', b'S', b'T', // value = "TEST"
];

Expand Down
Loading