1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2024-12-14 11:57:30 +00:00

Display anyhow error chains better

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)
This commit is contained in:
Cole Helbling 2024-10-15 13:23:18 -07:00
parent e5c8d2d509
commit 566ef5ebc3
2 changed files with 5 additions and 5 deletions

View file

@ -218,7 +218,7 @@ async fn get_nar(
Download::Url(url) => Ok(Redirect::temporary(&url).into_response()), Download::Url(url) => Ok(Redirect::temporary(&url).into_response()),
Download::AsyncRead(stream) => { Download::AsyncRead(stream) => {
let stream = ReaderStream::new(stream).map_err(|e| { let stream = ReaderStream::new(stream).map_err(|e| {
tracing::error!("Stream error: {e}"); tracing::error!(%e, "Stream error");
e e
}); });
let body = Body::from_stream(stream); let body = Body::from_stream(stream);
@ -255,7 +255,7 @@ async fn get_nar(
// TODO: Make num_prefetch configurable // TODO: Make num_prefetch configurable
// The ideal size depends on the average chunk size // The ideal size depends on the average chunk size
let merged = merge_chunks(chunks, streamer, storage, 2).map_err(|e| { let merged = merge_chunks(chunks, streamer, storage, 2).map_err(|e| {
tracing::error!("Stream error: {e}"); tracing::error!(%e, "Stream error");
e e
}); });
let body = Body::from_stream(merged); let body = Body::from_stream(merged);

View file

@ -57,10 +57,10 @@ pub enum ErrorKind {
/// The requested NAR has missing chunks and needs to be repaired. /// The requested NAR has missing chunks and needs to be repaired.
IncompleteNar, IncompleteNar,
/// Database error: {0} /// Database error: {0:#}
DatabaseError(AnyError), DatabaseError(AnyError),
/// Storage error: {0} /// Storage error: {0:#}
StorageError(AnyError), StorageError(AnyError),
/// Manifest serialization error: {0} /// Manifest serialization error: {0}
@ -69,7 +69,7 @@ pub enum ErrorKind {
/// Access error: {0} /// Access error: {0}
AccessError(super::access::Error), AccessError(super::access::Error),
/// General request error: {0} /// General request error: {0:#}
RequestError(AnyError), RequestError(AnyError),
/// Error from the common components. /// Error from the common components.