Skip to content

Commit 144916a

Browse files
committed
refactor: Replace thiserror with derive_more
1 parent 97fa935 commit 144916a

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ cli-completions = ["cli"]
5151
pipe-trait = "^0.4.0"
5252
smart-default = "^0.6.0"
5353
derive_more = "^0.99.17"
54-
thiserror = "^1.0.38"
5554
rayon = "^1.6.1"
5655
text-block-macros = "^0.1.1"
5756
rounded-div = "^0.1.2"

src/args/fraction.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
use derive_more::{AsRef, Deref, Display, Into};
1+
use derive_more::{AsRef, Deref, Display, Error, Into};
22
use std::{
33
convert::{TryFrom, TryInto},
44
num::ParseFloatError,
55
str::FromStr,
66
};
7-
use thiserror::Error;
87

98
/// Floating-point value that is greater than or equal to 0 and less than 1.
109
#[derive(Debug, Default, Clone, Copy, PartialEq, PartialOrd, AsRef, Deref, Display, Into)]
1110
pub struct Fraction(f32);
1211

1312
/// Error that occurs when calling [`Fraction::new`].
14-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
13+
#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, Error)]
1514
pub enum ConversionError {
1615
/// Provided value is greater than or equal to 1.
17-
#[error("greater than or equal to 1")]
16+
#[display(fmt = "greater than or equal to 1")]
1817
UpperBound,
1918
/// Provided value is less than 0.
20-
#[error("less than 0")]
19+
#[display(fmt = "less than 0")]
2120
LowerBound,
2221
}
2322

@@ -42,8 +41,7 @@ impl TryFrom<f32> for Fraction {
4241
}
4342
}
4443

45-
#[derive(Debug, Clone, PartialEq, Eq, Error)]
46-
#[error("{_0}")]
44+
#[derive(Debug, Display, Clone, PartialEq, Eq, Error)]
4745
pub enum FromStrError {
4846
ParseFloatError(ParseFloatError),
4947
Conversion(ConversionError),

src/bytes_format/parsed_value.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use thiserror::Error;
1+
use derive_more::{Display, Error};
22

33
/// Return value of [`Formatter::parse_value`](super::Formatter::parse_value).
4-
#[derive(Debug, Clone, Copy, Error)]
4+
#[derive(Debug, Display, Clone, Copy, Error)]
55
pub enum ParsedValue {
66
/// When input value is less than `scale_base`.
7-
#[error("{value} ")]
7+
#[display(fmt = "{value} ")]
88
Small {
99
/// Input value that is less than `scale_base`.
1010
value: u16,
1111
},
1212
/// When input value is greater than `scale_base`.
13-
#[error("{coefficient:.1}{unit}")]
13+
#[display(fmt = "{coefficient:.1}{unit}")]
1414
Big {
1515
/// The visible part of the number.
1616
coefficient: f32,

src/json_data/schema_version.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#[cfg(feature = "json")]
2+
use derive_more::{Display, Error};
3+
#[cfg(feature = "json")]
24
use serde::{Deserialize, Serialize};
35
#[cfg(feature = "json")]
46
use std::convert::TryFrom;
5-
#[cfg(feature = "json")]
6-
use thiserror::Error;
77

88
/// Content of [`SchemaVersion`].
99
pub const SCHEMA_VERSION: &str = "2021-06-05";
@@ -16,8 +16,8 @@ pub struct SchemaVersion;
1616

1717
/// Error when trying to parse [`SchemaVersion`].
1818
#[cfg(feature = "json")]
19-
#[derive(Debug, Error)]
20-
#[error("InvalidSchema: {:?}: input schema is not {:?}", input, SCHEMA_VERSION)]
19+
#[derive(Debug, Display, Error)]
20+
#[display(fmt = "InvalidSchema: {input:?}: input schema is not {SCHEMA_VERSION:?}")]
2121
pub struct InvalidSchema {
2222
/// The input string.
2323
pub input: String,

src/runtime_error.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
use thiserror::Error;
1+
use derive_more::{Display, Error};
22

33
/// Error caused by the CLI program.
4-
#[derive(Debug, Error)]
4+
#[derive(Debug, Display, Error)]
55
#[non_exhaustive]
66
pub enum RuntimeError {
77
/// When it fails to write JSON representation of
88
/// [DataTreeReflection](crate::data_tree::Reflection) to stdout.
9-
#[error("SerializationFailure: {_0}")]
9+
#[display(fmt = "SerializationFailure: {_0}")]
1010
SerializationFailure(serde_json::Error),
1111
/// When it fails to read JSON representation of
1212
/// [DataTreeReflection](crate::data_tree::Reflection) from stdin.
13-
#[error("DeserializationFailure: {_0}")]
13+
#[display(fmt = "DeserializationFailure: {_0}")]
1414
DeserializationFailure(serde_json::Error),
1515
/// When both `--json-input` and file names are both specified.
16-
#[error("JsonInputArgConflict: Arguments exist alongside --json-input")]
16+
#[display(fmt = "JsonInputArgConflict: Arguments exist alongside --json-input")]
1717
JsonInputArgConflict,
1818
/// When input JSON data is not a valid tree.
19-
#[error("InvalidInputReflection: {_0}")]
20-
InvalidInputReflection(String),
19+
#[display(fmt = "InvalidInputReflection: {_0}")]
20+
InvalidInputReflection(#[error(not(source))] String),
2121
}

0 commit comments

Comments
 (0)