Skip to content

trace --print-build-logs logs#471

Open
mrshmllow wants to merge 1 commit intotrunkfrom
marshmallow/p-kqrvwpxkulmm
Open

trace --print-build-logs logs#471
mrshmllow wants to merge 1 commit intotrunkfrom
marshmallow/p-kqrvwpxkulmm

Conversation

@mrshmllow
Copy link
Copy Markdown
Member

@mrshmllow mrshmllow commented Apr 29, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved build log handling so build log lines are correctly decoded, ANSI formatting is stripped, and messages are shown at the appropriate info level based on verbosity settings—resulting in clearer, more readable build output and better visibility into build progress and errors.

@github-actions github-actions Bot added rust Pull requests that update rust code release PRs against main labels Apr 29, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

Warning

Rate limit exceeded

@mrshmllow has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 43 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fd239a79-e2f2-40dd-969e-e1ea57cbe431

📥 Commits

Reviewing files that changed from the base of the PR and between 541a4f7 and 733b954.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • crates/core/src/commands/mod.rs
📝 Walkthrough

Walkthrough

ChildOutputMode::trace_slice now recognizes nix_compat::log::LogMessage::Result with ResultType::BuildLogLine, extracts the first Field::String, decodes it as UTF-8, and—if non-empty—passes the decoded text through existing ANSI-strip and Info-level logging/error-message logic.

Changes

Cohort / File(s) Summary
Log message handling
crates/core/src/commands/mod.rs
Extended ChildOutputMode::trace_slice to handle ResultType::BuildLogLine: extract first Field::String, UTF‑8 decode Cow bytes (borrowed or owned), and route non-empty decoded text through existing ANSI-stripping and Info-level dispatch. Added/used Field, ResultType, Cow, and core::str imports.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A build-line hopped in, tiny and bright,
I nibbled bytes until the text was right.
UTF‑8 decoded, no crumbs left to hide,
Stripped of color, then sent down the glide.
A cheerful trace, logged with rabbit pride.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'trace --print-build-logs logs' directly describes the main feature being implemented—handling build logs in the trace command with the --print-build-logs flag.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch marshmallow/p-kqrvwpxkulmm

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 24 minutes and 43 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/core/src/commands/mod.rs (1)

189-196: The first field assumption is correct per the Nix daemon protocol, but silent errors mask issues.

Line 194's assumption that fields[0] is Field::String is valid: the Nix daemon protocol specifies that resBuildLogLine (ResultType=101) contains exactly one String field with the log text. However, lines 195 and 202–205 silently drop log lines without any warning—either when the field is missing, not a String, or when UTF-8 decoding fails. This obscures failures that should be logged.

Consider emitting a debug or warn log when BuildLogLine parsing fails, so issues in the upstream logger become visible.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/core/src/commands/mod.rs` around lines 189 - 196, The
LogMessage::Result match arm handling ResultType::BuildLogLine currently
silently returns None when the first field is missing/not a String or when UTF-8
decoding fails; update the LogMessage::Result { r#type:
ResultType::BuildLogLine, fields, .. } branch to log a debug or warn (e.g.,
using tracing::warn! or crate logger) whenever fields.into_iter().next() is not
Field::String or when String::from_utf8/str::from_utf8 fails, including
contextual info (the actual Field variant or the decoding error) and still
return None; reference the LogMessage::Result match arm and
ResultType::BuildLogLine to locate the code to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/core/src/commands/mod.rs`:
- Around line 198-206: The code currently drops lines when UTF-8 decoding fails
by mapping to .ok(); instead, preserve the line using a lossy fallback: replace
the match that builds msg so invalid UTF-8 is converted with
String::from_utf8_lossy (producing a Cow<str>) instead of returning None. Update
the bytes branch to use
str::from_utf8(bytes).map(Cow::Borrowed).unwrap_or_else(|_|
String::from_utf8_lossy(bytes).into()) and the vec branch to use
String::from_utf8(vec).map(Cow::Owned).unwrap_or_else(|e|
String::from_utf8_lossy(&e.into_bytes()).into()), leaving the subsequent match
that yields (msg, VerbosityLevel::Info) intact.

---

Nitpick comments:
In `@crates/core/src/commands/mod.rs`:
- Around line 189-196: The LogMessage::Result match arm handling
ResultType::BuildLogLine currently silently returns None when the first field is
missing/not a String or when UTF-8 decoding fails; update the LogMessage::Result
{ r#type: ResultType::BuildLogLine, fields, .. } branch to log a debug or warn
(e.g., using tracing::warn! or crate logger) whenever fields.into_iter().next()
is not Field::String or when String::from_utf8/str::from_utf8 fails, including
contextual info (the actual Field variant or the decoding error) and still
return None; reference the LogMessage::Result match arm and
ResultType::BuildLogLine to locate the code to change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f9d1b3f-754b-49ff-9f4b-96ec9ac04483

📥 Commits

Reviewing files that changed from the base of the PR and between 6017853 and 5e82210.

📒 Files selected for processing (1)
  • crates/core/src/commands/mod.rs

Comment thread crates/core/src/commands/mod.rs Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
crates/core/src/commands/mod.rs (1)

200-210: ⚠️ Potential issue | 🟡 Minor

Use lossy UTF-8 fallback instead of dropping build-log lines.

Line 202 and Line 204 convert decode failures to None, and Line 209 drops the message. That loses potentially important diagnostics; preserve the line with from_utf8_lossy instead.

Suggested fix
-                let msg = match msg {
-                    std::borrow::Cow::Borrowed(bytes) => {
-                        str::from_utf8(bytes).map(Cow::Borrowed).ok()
-                    }
-                    std::borrow::Cow::Owned(vec) => String::from_utf8(vec).map(Cow::Owned).ok(),
-                };
-
-                match msg {
-                    Some(msg) => (msg, VerbosityLevel::Info),
-                    None => return None,
-                }
+                let msg = match msg {
+                    std::borrow::Cow::Borrowed(bytes) => {
+                        str::from_utf8(bytes)
+                            .map(Cow::Borrowed)
+                            .unwrap_or_else(|_| String::from_utf8_lossy(bytes))
+                    }
+                    std::borrow::Cow::Owned(vec) => match String::from_utf8(vec) {
+                        Ok(s) => Cow::Owned(s),
+                        Err(e) => String::from_utf8_lossy(&e.into_bytes()),
+                    },
+                };
+
+                (msg, VerbosityLevel::Info)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/core/src/commands/mod.rs` around lines 200 - 210, The current match on
msg (handling std::borrow::Cow variants) discards lines when UTF-8 decoding
fails because str::from_utf8(...) and String::from_utf8(...) map errors to None,
causing the function to return None; instead decode using from_utf8_lossy so
invalid UTF-8 is replaced with the Unicode replacement char and the line is
preserved. Update the Borrowed branch to use str::from_utf8_lossy(bytes) and the
Owned branch to use String::from_utf8_lossy(vec) (or convert Owned vec into a
lossy String), and keep the subsequent match returning (msg,
VerbosityLevel::Info) so malformed bytes become lossy Strings rather than being
dropped.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@crates/core/src/commands/mod.rs`:
- Around line 200-210: The current match on msg (handling std::borrow::Cow
variants) discards lines when UTF-8 decoding fails because str::from_utf8(...)
and String::from_utf8(...) map errors to None, causing the function to return
None; instead decode using from_utf8_lossy so invalid UTF-8 is replaced with the
Unicode replacement char and the line is preserved. Update the Borrowed branch
to use str::from_utf8_lossy(bytes) and the Owned branch to use
String::from_utf8_lossy(vec) (or convert Owned vec into a lossy String), and
keep the subsequent match returning (msg, VerbosityLevel::Info) so malformed
bytes become lossy Strings rather than being dropped.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0ae6f90-b725-4682-aa6f-9bcd6ae48a28

📥 Commits

Reviewing files that changed from the base of the PR and between 5e82210 and 541a4f7.

📒 Files selected for processing (1)
  • crates/core/src/commands/mod.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release PRs against main rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant