Skip to content

refactor: extend the error-message checker to format!-wrapped messages#3595

Merged
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3468-02
Jul 16, 2026
Merged

refactor: extend the error-message checker to format!-wrapped messages#3595
chet merged 1 commit into
NVIDIA:mainfrom
chet:gh-issue-3468-02

Conversation

@chet

@chet chet commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

A follow-up to #3566, as part of adopting the Rust API Guidelines convention (C-GOOD-ERR): that extends the lint-error-messages checker to reach messages wrapped in a format!. The original checker only saw a bare string literal, so CarbideError::invalid_argument(format!("Duplicate ...")) and .context(format!("Failed ...")) kept their capital lead -- and because the checker couldn't --fix them, those were the sites that drifted between source and test as #3566 landed.

  • leading_str_lit now peels a format!/format_args! down to its format-string literal, but only in the slots the checker already trusts -- a CarbideError/Status constructor or a .context/.wrap_err method. A bare format! (a log line, a command echo) is left alone, and {placeholder} names like {MachineId} are preserved.
  • --fix then lowercased 246 messages across 69 files that were previously invisible, with acronyms (VPC, EK), CamelCase types (RsaPublicKey), and placeholders preserved.
  • Updated the test assertions that pinned the old strings -- attestation, tpm-ca, site-explorer, ib-partition, and the duplicate-extension-services allocate path, whose format! source now rejoins its already-lowercased twin.

Manual impl Display/write! bodies and struct-literal error fields (CarbideError::Internal { message }) stay out of reach, still marked with the checker's TODO -- a further follow-up.

Continues #3566 · supports #3468

@chet
chet requested a review from a team as a code owner July 16, 2026 06:22
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This PR standardizes error-message casing, wording, and punctuation across Rust crates. It also extends the xtask checker to rewrite messages inside format! and format_args! expressions, with integration coverage.

Changes

Error message standardization

Layer / File(s) Summary
Agent runtime and command errors
crates/agent/..., crates/admin-cli/...
Timeout, configuration, file-operation, DPU, extension-service, monitoring, upgrade, and test error messages use normalized lowercase-leading wording.
API-core errors and tests
crates/api-core/...
Attestation, handler, allocation, provisioning, networking, credential, and validation messages are updated, with affected expected test strings adjusted.
Workspace support crates
crates/dns/..., crates/firmware/..., crates/network/..., crates/host-support/..., crates/ssh-console/..., crates/dpf/...
Error text is normalized across supporting services and test utilities.
Error-message checker
crates/xtask/src/error_message_case.rs, crates/xtask/src/workspace_deps.rs
The checker now recognizes leading literals inside formatting macros and verifies rewriting behavior end to end.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 82.98% 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.
Title check ✅ Passed The title accurately summarizes the checker enhancement for format!-wrapped error messages.
Description check ✅ Passed The description matches the implemented checker expansion and the related lowercasing/test updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 9

🧹 Nitpick comments (1)
crates/xtask/src/error_message_case.rs (1)

746-784: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover format_args! explicitly.

FORMAT_MACROS supports both spellings, but this integration test covers only format!. Add table-driven cases for format! and format_args! in error and non-error positions so the advertised format_args! behavior cannot regress unnoticed.

As per coding guidelines, “Use tables whenever two or more tests invoke the same operation with different inputs.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/xtask/src/error_message_case.rs` around lines 746 - 784, Extend the
end_to_end_rewrite_reaches_format test into table-driven cases covering both
format! and format_args! in error positions and non-error positions. Assert that
error-position invocations are rewritten while bare invocations remain
unchanged, preserving interpolation text and the existing log-macro coverage.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/admin-cli/src/instance/reboot/cmd.rs`:
- Line 31: Update the expected error string in
reboot_error_includes_instance_context_and_preserves_source to use the lowercase
“failed” casing now produced by the wrap_err_with message, while preserving the
rest of the assertion and source-error checks.

In `@crates/agent/src/agent_platform.rs`:
- Around line 62-64: Normalize the remaining file-operation error contexts in
the surrounding agent platform implementation, including the paths at the
referenced locations, to use the same lowercase wording as the updated
destination-file existence message. Preserve the existing errors and formatting
while changing only the inconsistent uppercase variants.

In `@crates/api-core/src/attestation/measured_boot.rs`:
- Line 225: Update the CarbideError::AttestBindKeyError message for the
fs::read(cred_out_path) failure to say “could not read creds file” instead of
“could not create creds file”, while leaving the surrounding error handling
unchanged.

In `@crates/api-core/src/handlers/dpu.rs`:
- Line 950: Update the error message in the DHCP timestamp parsing path to use
the standard uppercase “DHCP” acronym while preserving the normalized sentence
casing and existing error details.
- Around line 123-124: Update the discovery error messages in the DPU handler,
including the occurrences near the loopback-IP checks, to combine the subject
and cause into one grammatical clause. Ensure each message reads like “DPU
{dpu_machine_id} needs discovery because it does not have a loopback IP yet,”
preserving the existing error behavior.

In `@crates/api-core/src/handlers/expected_rack.rs`:
- Line 47: Update the expected-rack test assertions around the relevant cases in
expected_rack tests to match the new lowercase error message, changing the
expected substring from “Unknown rack_profile_id” to “unknown rack_profile_id”
while preserving the rest of each assertion.

In `@crates/api-core/src/handlers/ib_partition.rs`:
- Line 322: Update the error message in the partition-key mapping around the
pool return handling to use “returned” instead of “return,” preserving the
existing wording and error behavior.

In `@crates/api-core/src/handlers/instance.rs`:
- Around line 1696-1697: Update the error message in the
rpc_try_from(mh_snapshot) failure path to accurately state that the snapshot
could not be converted into an instance, replacing the contradictory “can be
converted” wording while preserving the existing machine_id context.

In `@crates/api-core/src/instance/mod.rs`:
- Around line 454-455: Update the operator-facing error messages near the shown
message and the referenced OS-image handling block: change “not support VF” to
“VF {} is not supported,” “image OS” to “OS image `{}` does not exist,” and
“failed to get OS image error” to “failed to get OS image: {e}.” Preserve the
existing placeholders and error-reporting behavior.

---

Nitpick comments:
In `@crates/xtask/src/error_message_case.rs`:
- Around line 746-784: Extend the end_to_end_rewrite_reaches_format test into
table-driven cases covering both format! and format_args! in error positions and
non-error positions. Assert that error-position invocations are rewritten while
bare invocations remain unchanged, preserving interpolation text and the
existing log-macro coverage.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2fdbec3f-6a0f-4beb-a120-809564110273

📥 Commits

Reviewing files that changed from the base of the PR and between 0d28ae5 and cf3658d.

📒 Files selected for processing (75)
  • crates/admin-cli/src/instance/reboot/cmd.rs
  • crates/agent/src/agent_platform.rs
  • crates/agent/src/containerd/command/bash_command.rs
  • crates/agent/src/dpu/interface.rs
  • crates/agent/src/dpu/link.rs
  • crates/agent/src/dpu/route.rs
  • crates/agent/src/ethernet_virtualization.rs
  • crates/agent/src/extension_services/k8s_pod_handler.rs
  • crates/agent/src/lib.rs
  • crates/agent/src/main_loop.rs
  • crates/agent/src/network_monitor.rs
  • crates/agent/src/tests/full.rs
  • crates/agent/src/tests/test_network_monitor.rs
  • crates/agent/src/upgrade.rs
  • crates/api-core/src/attestation/measured_boot.rs
  • crates/api-core/src/attestation/mod.rs
  • crates/api-core/src/attestation/tpm_ca_cert.rs
  • crates/api-core/src/compat.rs
  • crates/api-core/src/credentials/mod.rs
  • crates/api-core/src/db_init.rs
  • crates/api-core/src/dhcp/discover.rs
  • crates/api-core/src/ethernet_virtualization.rs
  • crates/api-core/src/handlers/api.rs
  • crates/api-core/src/handlers/bmc_endpoint_explorer.rs
  • crates/api-core/src/handlers/client_resolution.rs
  • crates/api-core/src/handlers/component_manager.rs
  • crates/api-core/src/handlers/compute_allocation.rs
  • crates/api-core/src/handlers/credential.rs
  • crates/api-core/src/handlers/dns.rs
  • crates/api-core/src/handlers/dpf.rs
  • crates/api-core/src/handlers/dpu.rs
  • crates/api-core/src/handlers/expected_rack.rs
  • crates/api-core/src/handlers/extension_service.rs
  • crates/api-core/src/handlers/host_reprovisioning.rs
  • crates/api-core/src/handlers/ib_partition.rs
  • crates/api-core/src/handlers/instance.rs
  • crates/api-core/src/handlers/instance_type.rs
  • crates/api-core/src/handlers/machine.rs
  • crates/api-core/src/handlers/machine_discovery.rs
  • crates/api-core/src/handlers/machine_identity.rs
  • crates/api-core/src/handlers/machine_interface.rs
  • crates/api-core/src/handlers/machine_validation.rs
  • crates/api-core/src/handlers/managed_host.rs
  • crates/api-core/src/handlers/network_security_group.rs
  • crates/api-core/src/handlers/network_segment.rs
  • crates/api-core/src/handlers/nmxc_browse.rs
  • crates/api-core/src/handlers/power_options.rs
  • crates/api-core/src/handlers/pxe.rs
  • crates/api-core/src/handlers/rack.rs
  • crates/api-core/src/handlers/redfish.rs
  • crates/api-core/src/handlers/site_explorer.rs
  • crates/api-core/src/handlers/sku.rs
  • crates/api-core/src/handlers/uefi.rs
  • crates/api-core/src/handlers/vpc.rs
  • crates/api-core/src/handlers/vpc_prefix.rs
  • crates/api-core/src/instance/mod.rs
  • crates/api-core/src/ipxe.rs
  • crates/api-core/src/measured_boot/rpc/journal.rs
  • crates/api-core/src/setup.rs
  • crates/api-core/src/tests/ib_instance.rs
  • crates/api-core/src/tests/instance.rs
  • crates/api-core/src/tests/measured_boot.rs
  • crates/api-core/src/tests/site_explorer.rs
  • crates/api-core/src/tests/tpm_ca.rs
  • crates/dns/src/lib.rs
  • crates/dpf/build.rs
  • crates/dpu-otel-agent/src/lib.rs
  • crates/dsx-exchange-consumer/src/api_client.rs
  • crates/firmware/src/downloader.rs
  • crates/host-support/src/registration.rs
  • crates/network/src/virtualization.rs
  • crates/ssh-console-mock-api-server/src/api.rs
  • crates/ssh-console/tests/util/ssh_client.rs
  • crates/xtask/src/error_message_case.rs
  • crates/xtask/src/workspace_deps.rs

Comment thread crates/admin-cli/src/instance/reboot/cmd.rs
Comment thread crates/agent/src/agent_platform.rs
Comment thread crates/api-core/src/attestation/measured_boot.rs
Comment thread crates/api-core/src/handlers/dpu.rs
Comment thread crates/api-core/src/handlers/dpu.rs
Comment thread crates/api-core/src/handlers/expected_rack.rs
Comment thread crates/api-core/src/handlers/ib_partition.rs
Comment thread crates/api-core/src/handlers/instance.rs
Comment thread crates/api-core/src/instance/mod.rs
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
boot-artifacts-x86_64 3 0 0 3 0 0
forge-admin-cli-x86_64 259 16 29 79 7 128
machine-validation-runner 532 39 113 184 15 181
machine_validation 532 39 113 184 15 181
machine_validation-aarch64 532 39 113 184 15 181
nvmetal-carbide 532 39 113 184 15 181
TOTAL 2390 172 481 818 67 852

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@chet
chet force-pushed the gh-issue-3468-02 branch 2 times, most recently from be3ef07 to 3fd3115 Compare July 16, 2026 08:44
The `lint-error-messages` checker from NVIDIA#3566 only saw a message passed as a bare string literal, so anything wrapped in a `format!` slipped through -- `CarbideError::invalid_argument(format!("Duplicate ..."))`, `.context(format!("Failed ..."))`, and friends kept their capital lead because the literal hid inside the macro. That was a documented gap, and it was the exact class that drifted between source and test while NVIDIA#3566 was landing: the checker couldn't `--fix` the source, so a hand-edited assertion could silently disagree with it. This teaches the checker to peel a wrapping `format!` when it sits in a slot we already treat as an error message, then sweeps what it now reaches.

Primary callouts are:

- `leading_str_lit` now peels a `format!`/`format_args!` macro down to its format-string literal, but only in the argument slots the checker already trusts -- a `CarbideError`/`Status` constructor or a `.context`/`.wrap_err` method. A bare `format!` (a log line, a `flint` command echo) is never touched, and the existing `{placeholder}` handling leaves interpolation names like `{MachineId}` intact.
- Ran `--fix` over what the widening reaches: it lowercased 246 previously-invisible messages across 69 files, all inside error constructs, with acronyms (`VPC`, `EK`), CamelCase types (`RsaPublicKey`, `MachineId`), and placeholders preserved.
- Updated the test assertions that pinned the old strings -- attestation, tpm-ca, site/rack explorers, machine discovery/interfaces, instance allocation, ib-partition, and the duplicate-extension-services allocate path, whose `format!` source is now swept so it rejoins its already-lowercased twin.

Manual `impl Display`/`write!` bodies and struct-literal error fields (`CarbideError::Internal { message }`) stay out of reach, still marked with the checker's `TODO` -- a further follow-up.

Tests added! -- `end_to_end_rewrite_reaches_format` drives the real span -> byte-range -> splice path across a `CarbideError` constructor and a `.context`, checks that `{MachineId}` survives, and asserts a bare `format!`/log macro is left alone.

This continues NVIDIA#3566 and supports NVIDIA#3468

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
@chet
chet force-pushed the gh-issue-3468-02 branch from 3fd3115 to d2c58f4 Compare July 16, 2026 08:52
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@chet
chet merged commit 976b016 into NVIDIA:main Jul 16, 2026
105 of 107 checks passed
@chet
chet deleted the gh-issue-3468-02 branch July 16, 2026 16:49
chet added a commit to chet/bare-metal-manager-core that referenced this pull request Jul 16, 2026
…fix hint

NVIDIA#3595 taught the `lint-error-messages` checker to peel a `format!` inside an expression-bodied closure (`.wrap_err_with(|| format!(...))`), but the common *block*-bodied form (`.wrap_err_with(|| { format!(...) })`) still slipped through -- the exact siblings CodeRabbit pointed at on NVIDIA#3595. This closes that gap, and while we're in the failure path, makes the "how do I fix this?" output impossible to miss for a contributor who trips the check.

Primary callouts are:

- `leading_str_lit` gains an `Expr::Block` arm that forwards to the block's tail expression, so a message behind `|| { format!(...) }` is reached just like the expression-bodied form. `--fix` then lowercased 19 messages across 5 files (agent file-ops, `k8s_pod_handler`, `hbn`, machine-controller scout scripts, and the xtask workspace-deps check).
- The report-mode failure now prints the rule, the exact `cargo xtask lint-error-messages --fix` command on its own line, and the `// xtask:allow-error-case` opt-out for a deliberate capital -- instead of a single sentence tacked onto the violation count.

Still out of reach, and marked in the checker `TODO` as the remaining follow-up: struct-literal error fields (`CarbideError::Internal { message: "..." }`, ~150 sites), manual `impl Display`/`write!` bodies, and macro-body-nested sites.

Tests added! -- `end_to_end_rewrite_reaches_block_closure` drives the real span -> byte-range -> splice path through a `.wrap_err_with(|| { format!(...) })` and checks the `{host}` interpolation survives.

This continues NVIDIA#3595 and supports NVIDIA#3468

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
chet added a commit that referenced this pull request Jul 16, 2026
…fix hint (#3613)

## Summary

A small follow-up to #3595. That PR reached `format!` inside
*expression*-bodied closures (`.wrap_err_with(|| format!(...))`); this
closes the sibling gap for *block*-bodied closures (`.wrap_err_with(|| {
format!(...) })`) — the exact form CodeRabbit flagged there — and makes
the checker's failure output easy for a contributor to act on.

- `leading_str_lit` gains an `Expr::Block` arm (forward to the block's
tail expression), so `|| { format!(...) }` is reached just like `||
format!(...)`. `--fix` lowercased **19 messages across 5 files** (agent
file-ops, `k8s_pod_handler`, `hbn`, machine-controller scout scripts,
and the xtask workspace-deps check).
- The report-mode failure now prints the rule, the exact `cargo xtask
lint-error-messages --fix` command on its own line, and the `//
xtask:allow-error-case` opt-out for a deliberate capital — instead of a
one sentence tacked onto the violation count.

Still deferred, and documented in the checker `TODO`: struct-literal
error fields (`CarbideError::Internal { message: "..." }`, ~150 sites),
manual `Display`/`write!` bodies, and macro-body-nested sites.

Continues #3595 · supports #3468

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
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