Skip to content

feat: display output of failed builds#125

Merged
viviveevee merged 14 commits intomainfrom
SDK-2305-display-failed-build-output
Oct 14, 2025
Merged

feat: display output of failed builds#125
viviveevee merged 14 commits intomainfrom
SDK-2305-display-failed-build-output

Conversation

@viviveevee
Copy link
Copy Markdown
Contributor

@viviveevee viviveevee commented Oct 10, 2025

Currently, when a build fails, the error is not visible to the user. It is only briefly displayed in the rolling 4-line buffer. With this PR, the build step outputs are buffered, and for every build that fails, the output is displayed with a readable report.

Example (remaining) output:

Build output for canister my-canister:

Building: script (command: bash -c 'for i in 1 2 3 4 5; do echo "Processing step $i"; sleep 1; done') 1 of 3
Processing step 1
Processing step 2
Processing step 3
Processing step 4
Processing step 5

Building: script (command: echo "Step 2 completed") 2 of 3
Step 2 completed

Building: script (command: bash -c 'for i in 1 2 3 4 5; do echo "Compiling module $i"; done; echo "ERROR Build failed"; exit 1') 3 of 3
Compiling module 1
Compiling module 2
Compiling module 3
Compiling module 4
Compiling module 5
ERROR Build failed
Failed to build canister: command 'bash -c 'for i in 1 2 3 4 5; do echo "Compiling module $i"; done; echo "ERROR Build failed"; exit 1'' failed with status code 1
Error: One or more canisters failed to build

https://dfinity.atlassian.net/browse/SDK-2305

@viviveevee viviveevee marked this pull request as ready for review October 10, 2025 09:07
@viviveevee viviveevee requested a review from a team as a code owner October 10, 2025 09:07
Copy link
Copy Markdown
Contributor

@raymondk raymondk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out in the examples/icp-progress-bar-test-bed example.

[canister-1] ✺
Building: script (command: sh -c 'for i in $(seq 1 20); do echo "failing build step $i"; done; exit 1') 3 of 4
> failing build step 10
> failing build step 11
> failing build step 12
> failing build step 13

[canister-2] ✔ Built successfully
[canister-3] ✔ Built successfully                                                                                                                                                                                                                                                  Build output for canister canister-1:

Building: script (command: lorem.sh 5) 1 of 4
Running command: lorem.sh 5
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Building: script (command: lorem.sh 5) 2 of 4
Running command: lorem.sh 5
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Building: script (command: sh -c 'for i in $(seq 1 20); do echo "failing build step $i"; done; exit 1') 3 of 4
Running command: sh -c 'for i in $(seq 1 20); do echo "failing build step $i"; done; exit 1'
failing build step 1
failing build step 2
failing build step 3
failing build step 4
failing build step 5
failing build step 6
failing build step 7
failing build step 8
failing build step 9
failing build step 10
failing build step 11
failing build step 12
[canister-1] ✘ Failed to build canister: command 'sh -c 'for i in $(seq 1 20); do echo "failing build step $i"; done; exit 1'' failed with status code 1
[canister-2] ✔ Built successfully
[canister-3] ✔ Built successfully                                                                                                                                                                                                                                                  Error: command 'sh -c 'for i in $(seq 1 20); do echo "failing build step $i"; done; exit 1'' failed with status code 1```

A couple of observations:
- I think the last line might not be necessary since it's alredy under [canister-1]
- It looks like the "built successfully" is duplicated (maybe that is intentional, i think it's nice to have a summary at the bottom)
- The first line `[canister-1] *` still looks like it's in progress.

Comment thread crates/icp-cli/src/commands/build/mod.rs Outdated
Comment thread crates/icp-cli/tests/build_tests.rs Outdated
Comment thread crates/icp-cli/tests/build_tests.rs
Comment thread crates/icp-cli/src/progress.rs
let script_handler = ScriptProgressHandler::new(pb.clone(), pb_hdr.clone());

// Setup script progress handling and receiver join handle
let (tx, rx) = script_handler.setup_output_handler();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this script_handler and setup_output_handler if you are now handling output in the command itself? Can the script handler not be made to support outputting failure information as well? The point was to remove the burden of handling these details from the command (I believe this applies to build and sync both).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked output display significantly. It's now all handled by the progress bar

Comment thread crates/icp-cli/src/commands/build/mod.rs Outdated
Comment thread crates/icp-cli/src/progress.rs Outdated
Comment thread crates/icp-cli/tests/build_tests.rs
Comment thread crates/icp-cli/tests/build_tests.rs Outdated
Comment thread crates/icp/src/canister/build.rs
Comment thread crates/icp/src/canister/prebuilt.rs Outdated
SourceField::Local(s) => {
stdio
.send(format!("Reading local file: {}", s.path))
.await?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never actually be displayed to the user, right? Because it will (likely) finish almost instantly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will not be visible if everything works out fine, but if there is an error it will show up in the full error output

Comment thread crates/icp/src/canister/prebuilt.rs Outdated

// Verify the checksum if it's provided
if let Some(expected) = &adapter.sha256 {
stdio.send("Verifying checksum".to_string()).await?;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above - will it actually get shown, if it completes almost instantly?

Comment thread crates/icp/src/canister/script.rs Outdated
Comment thread crates/icp/src/canister/script.rs Outdated
Comment thread crates/icp-cli/src/commands/build/mod.rs Outdated
Comment on lines +153 to +158
// After progress bar is finished, dump the output if build failed
if let Err(e) = &result {
pb.dump_output(ctx);
let _ = ctx
.term
.write_line(&format!("Failed to build canister: {e}"));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut feeling says there's still some way for the output to get messed up because of progress bars, but I don't see anything specific.

Comment thread crates/icp-cli/src/progress.rs Outdated
Comment thread crates/icp-cli/tests/build_tests.rs
Copy link
Copy Markdown
Contributor

@rikonor rikonor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just left one nitpick about the naming of SomeProgressBar.

@viviveevee viviveevee merged commit 8ab1cc5 into main Oct 14, 2025
37 checks passed
@viviveevee viviveevee deleted the SDK-2305-display-failed-build-output branch October 14, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants