Skip to content

Commit

Permalink
Display anyhow error chains better
Browse files Browse the repository at this point in the history
The default Display / `{}` formatter only shows the outermost error. We
have to use `{:#}` to show all the errors in the chain. This will make
stream errors somewhat more informational.

Before:

    Stream error: Storage error: service error

After:

    Stream error e=Storage error: service error: NoSuchKey: The specified key does not exist.: NoSuchKey: The specified key does not exist.

(after I manually mucked with the DB to change the S3 url for an item to
a non-existent name)
  • Loading branch information
cole-h committed Oct 15, 2024
1 parent e5c8d2d commit 566ef5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/src/api/binary_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async fn get_nar(
Download::Url(url) => Ok(Redirect::temporary(&url).into_response()),
Download::AsyncRead(stream) => {
let stream = ReaderStream::new(stream).map_err(|e| {
tracing::error!("Stream error: {e}");
tracing::error!(%e, "Stream error");
e
});
let body = Body::from_stream(stream);
Expand Down Expand Up @@ -255,7 +255,7 @@ async fn get_nar(
// TODO: Make num_prefetch configurable
// The ideal size depends on the average chunk size
let merged = merge_chunks(chunks, streamer, storage, 2).map_err(|e| {
tracing::error!("Stream error: {e}");
tracing::error!(%e, "Stream error");
e
});
let body = Body::from_stream(merged);
Expand Down
6 changes: 3 additions & 3 deletions server/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ pub enum ErrorKind {
/// The requested NAR has missing chunks and needs to be repaired.
IncompleteNar,

/// Database error: {0}
/// Database error: {0:#}
DatabaseError(AnyError),

/// Storage error: {0}
/// Storage error: {0:#}
StorageError(AnyError),

/// Manifest serialization error: {0}
Expand All @@ -69,7 +69,7 @@ pub enum ErrorKind {
/// Access error: {0}
AccessError(super::access::Error),

/// General request error: {0}
/// General request error: {0:#}
RequestError(AnyError),

/// Error from the common components.
Expand Down

0 comments on commit 566ef5e

Please sign in to comment.