Skip to content

refactor(init): replace expect with anyhow context in nushell completions - #2638

Merged
max-sixty merged 1 commit into
mainfrom
fix/init-expect-25481754388
May 7, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix/init-expect-25481754388

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

Replace .expect() calls with ? and .context() in handle_completions's nushell branch. The function returns anyhow::Result<()>, and CLAUDE.md's Error Handling section forbids .expect()/.unwrap() in Result-returning functions.

Changed in src/commands/init.rs:67-70:

  • init.generate().expect("Failed to generate nushell integration") → init.generate().context("failed to generate nushell integration")?
  • write!(stdout, ...).expect("Failed to write to stdout") → write!(stdout, ...).context("failed to write to stdout")?

Why no new test

The success path is already covered by tests/integration_tests/completion.rs::test_static_completions_for_all_shells, which exercises wt config shell completions nu and asserts non-empty output. The .expect() calls only fire on the failure path (a malformed template or closed stdout) — neither has a feasible reproduction in our test infrastructure, and CLAUDE.md acknowledges that pure code-quality improvements may not have a regression test.

Surfaced by

The 2026-05-07 nightly file survey, which found these .expect() calls flagged against CLAUDE.md's "no .expect()/.unwrap() in Result-returning functions" rule.

…letions

Replace two .expect() calls in handle_completions with ? and .context().
CLAUDE.md forbids .expect()/.unwrap() in Result-returning functions; the
existing calls would panic on init.generate() failure or stdout write
failure rather than returning a clean anyhow::Error.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@worktrunk-bot worktrunk-bot added the nightly-cleanup Issues found by nightly code quality sweep label May 7, 2026
@max-sixty
max-sixty merged commit d91ec63 into main May 7, 2026
25 checks passed
@max-sixty
max-sixty deleted the fix/init-expect-25481754388 branch May 7, 2026 08:06
This was referenced May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nightly-cleanup Issues found by nightly code quality sweep

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants