Skip to content

feat(command): let handlers attach warnings to the result envelope - #131

Open
jpage-godaddy wants to merge 1 commit into
mainfrom
allow-adding-warnings
Open

jpage-godaddy wants to merge 1 commit into
mainfrom
allow-adding-warnings

Conversation

@jpage-godaddy

Copy link
Copy Markdown
Collaborator

Summary

  • Adds CommandResult::with_warning(msg) so a handler that succeeds can still surface non-fatal warnings. The envelope already had a warnings field and Envelope::add_warning, but CommandResult had no way to reach them.
  • Middleware copies the warnings onto the success envelope. JSON and TOON output already serialize the whole envelope; warnings is omitted when empty.
  • Human output previously never rendered warnings. It now prints a Warnings: block ahead of Next steps:, including for commands with a custom human view.
  • CommandResultMetadata is #[non_exhaustive], so the new field is not a breaking change.

Known limits

  • raw_output commands render only the verbatim string, so warnings appear in the envelope but not in the printed text.
  • Streaming commands return no CommandResult and are unchanged.

Test plan

  • tests/warnings.rs: end-to-end through Cli::run for JSON (ordering), TOON, human, and absence when no warnings
  • Human renderer unit tests (placement before Next steps:, no block when empty)
  • fmt, clippy -D warnings, rustdoc -D warnings, cargo test --all-targets, cargo test --doc, module-size check, missing-docs count is zero

🤖 Generated with Claude Code

The envelope already had a `warnings` field, but nothing populated it and a
handler could not reach it. Add `CommandResult::with_warning`, carry the
messages through middleware onto the success envelope, and render them as a
"Warnings:" block in human output (JSON and TOON already serialize them).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

Static review identified no blocking issues in the additive API, warning propagation, rendering, or supplied tests; tests were not executed during this review.

No open issues 🎉

What changed in this PR

Adds handler-supplied, non-fatal warnings to the existing result envelope, allowing successful commands to report partial results or other caveats.

Changes:

  • Adds CommandResult::with_warning and propagates warnings through middleware.
  • Displays warnings before “Next steps” in human output, including custom views.
  • Documents the API and adds integration and renderer tests.
File Description
cli-engine/​tests/​warnings.rs Tests warning ordering, output formats, and omission when empty.
cli-engine/​src/​output/​human/​tests/​footer.rs Tests warning placement and absence when empty.
cli-engine/​src/​output/​human/​mod.rs Integrates warnings into standard and custom human rendering.
cli-engine/​src/​output/​human/​footer.rs Adds the warnings block formatter.
cli-engine/​src/​middleware/​run.rs Copies result warnings into the success envelope.
cli-engine/​src/​command/​mod.rs Adds the warning builder method and metadata field.
cli-engine/​docs/​concepts.md Documents handler warnings with an example.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants