Skip to content

Standardize error messages on the Rust API Guidelines, enforced at build time #3468

Description

@chet

Our error messages have no casing convention, and it shows -- "Failed to X" sits right next to "failed to X", "Error" next to "error", split almost 50/50 across the tree. Let's adopt the Rust API Guidelines convention (C-GOOD-ERR) -- lowercase first word, no trailing period -- so an error's Display text composes cleanly when it gets wrapped into a larger chain, and add a build-time lint so it stays that way. This is the errors half; logging is a separate follow-up.

What this involves

  • A syn-based cargo xtask lint-error-messages check (stable Rust -- casing is purely syntactic, so unlike carbide-lints it needs no borrow-checker). It inspects the message literal in #[error(...)], anyhow!/bail!/eyre!/ensure!, .context()/.wrap_err(), and NicoError/Status constructors, and flags a first word that's a capitalized normal word, or a trailing period. --fix rewrites offenders in place.
  • All-caps acronyms (BMC, DHCP, DPU) are casing-neutral and stay; mixed-case proper nouns (Redfish, Vault) get lowercased like any other word. // xtask:allow-error-case on or above a line opts it out.
  • Run --fix across the tree -- ~900 messages in ~40 crates -- and update the tests that assert the old strings. Panics / expect / assert are out of scope (not Error Display, and already mostly lowercase).
  • Wire it into the lint gate (cargo make lint-error-messages + a CI step next to carbide-lints) and document the convention in STYLE_GUIDE.md.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Fields

No fields configured for Enhancement.

Projects

Status
Triage

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions