bootc icon indicating copy to clipboard operation
bootc copied to clipboard

Improve error reporting by printing error chain sources

Open Johan-Liebert1 opened this issue 9 months ago • 2 comments

While working on integrating composefs-rs, received this error

ERROR Installing to disk: Creating composefs deployment: Failed to create image proxy: error

The actual error occurred deep into the containers-image-proxy crate and was a bit difficult to track down. After this patch below is what the error reporting looks like

ERROR Installing to disk: Creating composefs deployment: Failed to create image proxy: error
0: Error {
    context: "Failed to create image proxy",
    source: Other(
        "skopeo proxy unexpectedly exited during request method Initialize: exit status: 125\nError: please use unshare with rootless\n",
    ),
}
1: Other(
    "skopeo proxy unexpectedly exited during request method Initialize: exit status: 125\nError: please use unshare with rootless\n",
)

This is more for better dev-ex, so please let me know if this should be behind some sort of flag, like something similar to BOOTC_ERR_TRACE=1

Johan-Liebert1 avatar Apr 16 '25 05:04 Johan-Liebert1

Thanks for your patch! A minor procedural thing but this project tends to use "topic prefixes", so can you add e.g. cli: or so as a prefix? Also hopefully most patches are improvements, and the "imperative mood" is preferred so this could be condensed to just e.g.:

cli: Print error chain sources

Anyways on the actual code change. Yeah, today we use the "alternative printer" for anyhow which formats errors as a single line. I have personally felt in the past this is more readable than the default, especially as we use the #[context] attribute somewhat liberally.

In this specific case...I'm confused as to why we're only getting error at the end and not the full source. It maybe relates to our use of thiserror in the proxy crate?

This is more for better dev-ex, so please let me know if this should be behind some sort of flag, like something similar to BOOTC_ERR_TRACE=1

Perhaps when -v is used (ref https://github.com/containers/bootc/pull/1154 ) we could also change how errors are printed to be more verbose.

In this specific case though it seems to me we should just fix the proxy code right?

Offhand I wonder if we should change https://github.com/containers/containers-image-proxy-rs/blob/832795839fb71ae9aba11dc1a8d86f029adb7f1a/src/imageproxy.rs#L35C1-L35C48 to use #[from] instead?

cgwalters avatar Apr 16 '25 12:04 cgwalters

Thanks for the review. Updated the commit message, I read the docs about commit message format but forgot them while actually committing.

In this specific case...I'm confused as to why we're only getting error at the end and not the full source

Seems like this is intentional behaviour on anyhow's end https://docs.rs/anyhow/1.0.28/anyhow/struct.Error.html#display-representations

The docs say {:?} will print a backtrace, but I guess that's only true in case of a panic?

Perhaps when -v is used

https://github.com/bootc-dev/bootc/pull/1154 seems to be WIP as of now, but yes we could definitely have more verbose error reporting.

In this specific case though it seems to me we should just fix the proxy code right?

But, the fact still remains that anyhow will only print the error message on the top of the stack, so we will still end up missing out on printing the root cause.

Johan-Liebert1 avatar Apr 17 '25 05:04 Johan-Liebert1