Emit --json error envelopes through one json_envelope::emit_error: the builder is written 5 times and the human branch drifted

Offen
#1,924 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Refactoring
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
rust
Bereich
cli

Rechercherichtung

Start in crates/socket-patch-cli/src/json_envelope.rs around usage_error_json and usage_error (L669-L700), then compare the duplicates in commands/lock_cli.rs (error_envelope), commands/rollback.rs, commands/remove.rs (emit_error_envelope) and commands/scan/hosted.rs. Run the usage_error_json tests and the manifest_not_found tests first to pin current output. Done when one json_envelope::emit_error helper replaces the duplicates, --json output is byte-identical, and only the usage_error human line changes to sentence case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

agent:triaged arch-audit priority:p3 refactor

[agent] Filed by the scheduled architecture audit (audit-cli-tests). Register: T20.

Kind: refactor. Register ID: T20.

Problem

"Build an Envelope with status: error, print it under --json, else print Error: … to stderr" has no shared helper. It is written out in five places at cbbbdb9:

  • json_envelope.rs L669-L700: usage_error_json + usage_error. It hand-writes println! + to_string_pretty instead of ui::print_json, and prints Error: {message} raw.
  • lock_cli.rs L191-L201: error_envelope, plus emit. The human branch adds a hint.
  • rollback.rs L903-L908: its own error_envelope. rollback also open-codes 4 more branches beside it.
  • remove.rs L122-L132: emit_error_envelope. The human branch sentence-cases the message.
  • scan/hosted.rs L80-L91: json_error_envelope. It starts from a partial scan envelope, which is legitimately different.

The same pattern is also hand-written in repair.rs (L78, L143, L257), list.rs L219 and scan/mod.rs L1530.

The function bodies are identical: Envelope::new(cmd), set dry_run, then mark_error(EnvelopeError::new(code, msg)). The human branch has drifted three ways:

  • usage_error prints the message raw;
  • remove sentence-cases it;
  • lock_cli appends a hint.
// remove.rs
let mut env = Envelope::new(Command::Remove);
env.dry_run = dry_run;
env.mark_error(EnvelopeError::new(code, message));
println!("{}", env.to_pretty_json());
} else { eprintln!("Error: {}", crate::ui::sentence_case(&message)); }

Proposed change

  1. Add Envelope::error(command, dry_run, EnvelopeError) -> Envelope in json_envelope.rs.
  2. Add json_envelope::emit_error(command, json, dry_run, EnvelopeError). It prints with ui::print_json under --json; otherwise it prints Error: {sentence_case(message)} to stderr.
  3. Make usage_error call emit_error and return 2.
  4. Delete lock_cli::error_envelope, rollback::error_envelope and remove::emit_error_envelope, and call the helper from repair, list and scan.
  5. lock_cli keeps its hint as a second eprintln!.

Size

About 8 files, roughly -60/+25 lines.

Acceptance criteria

  • Every --json error document is byte-identical to today's. These guard it:
    • the usage_error_json tests in json_envelope.rs;
    • the lock_cli error_envelope tests;
    • the rollback/remove manifest_not_found tests;
    • tests/common/envelope.rs users.
  • usage_error's human line becomes sentence-cased. That is the one intended human-text change; say so in the PR.
  • No Envelope::new(..) followed by mark_error remains outside json_envelope.rs, except scan's partial-envelope case.
Vorherrschende Sprache
Rust
Sterne
9
Forks
2
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
309

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus SocketDev/socket-patch

Alle Issues in SocketDev/socket-patch

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.