Skip to content

Commit 23eb97c

Browse files
Do not include error sources in Display formatting
The source chain is traversed when reporting the error, so if the source is included in the Display formatting, it is reported twice.
1 parent 5e836f8 commit 23eb97c

6 files changed

Lines changed: 36 additions & 23 deletions

File tree

‎libs/opsqueue_python/src/errors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub type CPyResult<T, E> = Result<T, CError<E>>;
7070
/// allowing things like `KeyboardInterrupt`, `SystemExit` or `MemoryError`,
7171
/// to trigger cleanup-and-exit.
7272
#[derive(thiserror::Error, Debug)]
73-
#[error("Fatal Python exception: {0}")]
73+
#[error("Fatal Python exception")]
7474
pub struct FatalPythonException(#[from] pub PyErr);
7575

7676
impl From<CError<FatalPythonException>> for PyErr {

‎opsqueue/src/common/errors.rs‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ use super::{
1616
submission::{SubmissionCancelled, SubmissionCompleted, SubmissionFailed, SubmissionId},
1717
};
1818

19-
// #[derive(Error, Debug, Clone, Serialize, Deserialize)]
20-
// #[error("Low-level database error: {0:?}")]
21-
// pub struct DatabaseError(#[from] pub serde_error::Error);
2219
#[cfg_attr(feature = "server-logic", derive(Error, Debug))]
23-
#[cfg_attr(feature = "server-logic", error("Low-level database error: {0:?}"))]
20+
#[cfg_attr(feature = "server-logic", error("Low-level database error"))]
2421
#[cfg(feature = "server-logic")]
2522
pub struct DatabaseError(#[from] pub sqlx::Error);
2623

@@ -136,7 +133,7 @@ impl<L, R1, R2> From<E<R1, R2>> for E<L, E<R1, R2>> {
136133
}
137134

138135
#[derive(Error, Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
139-
#[error("You are using Opsqueue incorrectly. Details: {0}")]
136+
#[error("You are using Opsqueue incorrectly")]
140137
pub struct IncorrectUsage<E>(#[from] pub E);
141138

142139
#[derive(Error, Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]

‎opsqueue/src/common/mod.rs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,30 @@ impl std::fmt::Display for MaxSubmissions {
5151
}
5252
}
5353

54+
impl std::str::FromStr for MaxSubmissions {
55+
type Err = ParseMaxSubmissionsError;
56+
fn from_str(s: &str) -> Result<Self, Self::Err> {
57+
let value: NonZero<u64> = s.parse()?;
58+
Ok(MaxSubmissions::new(value)?)
59+
}
60+
}
61+
5462
#[derive(Debug, thiserror::Error)]
5563
pub enum ParseMaxSubmissionsError {
5664
#[error(transparent)]
57-
NotANumber(#[from] std::num::ParseIntError),
65+
NotANumber(std::num::ParseIntError),
5866
#[error(transparent)]
59-
TooLarge(#[from] MaxSubmissionsTooLarge),
67+
TooLarge(MaxSubmissionsTooLarge),
6068
}
6169

62-
impl std::str::FromStr for MaxSubmissions {
63-
type Err = ParseMaxSubmissionsError;
64-
fn from_str(s: &str) -> Result<Self, Self::Err> {
65-
let value: NonZero<u64> = s.parse()?;
66-
Ok(MaxSubmissions::new(value)?)
70+
impl From<std::num::ParseIntError> for ParseMaxSubmissionsError {
71+
fn from(value: std::num::ParseIntError) -> Self {
72+
Self::NotANumber(value)
73+
}
74+
}
75+
76+
impl From<MaxSubmissionsTooLarge> for ParseMaxSubmissionsError {
77+
fn from(value: MaxSubmissionsTooLarge) -> Self {
78+
Self::TooLarge(value)
6779
}
6880
}

‎opsqueue/src/consumer/client.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ impl Client {
519519

520520
#[derive(thiserror::Error, Debug)]
521521
pub enum InternalConsumerClientError {
522-
#[error("Low-level error in the websocket connection: {0}")]
522+
#[error("Low-level error in the websocket connection")]
523523
LowLevelWebsocketError(#[from] tokio_tungstenite::tungstenite::Error),
524524
#[error(
525-
"The oneshot channel to receive a sync response to an earlier request was dropped before a response was received: {0}"
525+
"The oneshot channel to receive a sync response to an earlier request was dropped before a response was received"
526526
)]
527527
OneshotSenderDropped(#[from] RecvError),
528528
#[error("Expected the sync response of kind {expected} but received {actual:?}")]

‎opsqueue/src/object_store/mod.rs‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ impl std::fmt::Display for ChunkType {
5050
#[derive(thiserror::Error, Debug)]
5151
pub enum ChunkRetrievalError {
5252
#[error(
53-
"Failed to retrieve chunk ({submission_prefix}, {chunk_index}, {chunk_type}) from object store: {source}"
53+
"Failed to retrieve chunk ({submission_prefix}, {chunk_index}, {chunk_type}) from object store"
5454
)]
5555
ObjectStoreError {
56+
#[source]
5657
source: object_store::Error,
5758
submission_prefix: Box<str>,
5859
chunk_index: chunk::ChunkIndex,
@@ -63,19 +64,21 @@ pub enum ChunkRetrievalError {
6364
#[derive(thiserror::Error, Debug)]
6465
pub enum ChunkStorageError {
6566
#[error(
66-
"Failed to store chunk ({submission_prefix}, {chunk_index}, {chunk_type}) to object store: {source}"
67+
"Failed to store chunk ({submission_prefix}, {chunk_index}, {chunk_type}) to object store"
6768
)]
6869
ObjectStoreError {
70+
#[source]
6971
source: object_store::Error,
7072
submission_prefix: Box<str>,
7173
chunk_index: chunk::ChunkIndex,
7274
chunk_type: ChunkType,
7375
},
74-
#[error("Failed to read chunk element from stream/iterator at index {chunk_index}: ")]
76+
#[error("Failed to read chunk element from stream/iterator at index {chunk_index}")]
7577
ChunkContentsEvalError {
7678
submission_prefix: Box<str>,
7779
chunk_index: chunk::ChunkIndex,
7880
chunk_type: ChunkType,
81+
#[source]
7982
source: anyhow::Error,
8083
},
8184
}
@@ -84,19 +87,20 @@ pub enum ChunkStorageError {
8487
pub enum ChunksStorageError {
8588
#[error(transparent)]
8689
ChunkStorageError(#[from] ChunkStorageError),
87-
#[error("Failed to read chunk element from stream/iterator: {source}")]
90+
#[error("Failed to read chunk element from stream/iterator")]
8891
ChunkContentsEvalError {
8992
submission_prefix: Box<str>,
9093
chunk_type: ChunkType,
94+
#[source]
9195
source: anyhow::Error,
9296
},
9397
}
9498

9599
#[derive(thiserror::Error, Debug)]
96100
pub enum NewObjectStoreClientError {
97-
#[error("Failed to parse URL: {0}")]
101+
#[error("Failed to parse URL")]
98102
UrlParseFailure(#[from] url::ParseError),
99-
#[error("URL is not valid object store URL {0}")]
103+
#[error("URL is not valid object store URL")]
100104
ObjectStoreUrlFailure(#[from] object_store::Error),
101105
}
102106

‎opsqueue/src/producer/client.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ impl Client {
337337

338338
#[derive(thiserror::Error, Debug)]
339339
pub enum InternalProducerClientError {
340-
#[error("HTTP request failed: {0}")]
340+
#[error("HTTP request failed")]
341341
HTTPClientError(#[from] reqwest::Error),
342-
#[error("Error decoding JSON response: {0}")]
342+
#[error("Error decoding JSON response")]
343343
ResponseDecodingError(#[from] serde_json::Error),
344344
#[error("Internal client received unexpected status: {0}")]
345345
UnexpectedStatus(StatusCode),

0 commit comments

Comments
 (0)