From c0ba176dee720947ea4c99cce08a2b256f7e21a6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 7 Nov 2022 10:53:00 -0500 Subject: [PATCH] Add error context with method name This will make it much more obvious in errors which proxy operation we're doing. Right now we can get e.g. a bare error message like "Deserializing value: Expected sequence, not null" e.g. Signed-off-by: Colin Walters --- src/imageproxy.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/imageproxy.rs b/src/imageproxy.rs index e7a1b68..5e94ead 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -304,12 +304,12 @@ impl ImageProxy { let mut childwait = self.childwait.lock().await; tokio::select! { r = req => { - Ok(r?) + Ok(r.with_context(|| format!("Failed to invoke skopeo proxy method {method}"))?) } r = childwait.as_mut() => { let r = r??; let stderr = String::from_utf8_lossy(&r.stderr); - return Err(anyhow::anyhow!("proxy unexpectedly exited during request method {}: {}\n{}", method, r.status, stderr)) + return Err(anyhow::anyhow!("skopeo proxy unexpectedly exited during request method {}: {}\n{}", method, r.status, stderr)) } } } @@ -380,7 +380,8 @@ impl ImageProxy { img: &OpenedImage, ) -> Result<(String, oci_spec::image::ImageManifest)> { let (digest, raw) = self.fetch_manifest_raw_oci(img).await?; - let manifest = serde_json::from_slice(&raw)?; + let manifest = + serde_json::from_slice(&raw).context("Deserializing manifest from skopeo")?; Ok((digest, manifest)) } @@ -400,7 +401,7 @@ impl ImageProxy { img: &OpenedImage, ) -> Result { let raw = self.fetch_config_raw(img).await?; - Ok(serde_json::from_slice(&raw)?) + Ok(serde_json::from_slice(&raw).context("Deserializing config from skopeo")?) } /// Fetch a blob identified by e.g. `sha256:`.