Skip to content

fix: surface invalid MINIMAL_INDEX_SOURCE as a clean error instead of a panic - #1132

Merged
norrietaylor merged 1 commit into
mainfrom
inbox-patch/mctx-index-source-clean-error-6859362e6b82c5bb
Jul 31, 2026
Merged

fix: surface invalid MINIMAL_INDEX_SOURCE as a clean error instead of a panic#1132
norrietaylor merged 1 commit into
mainfrom
inbox-patch/mctx-index-source-clean-error-6859362e6b82c5bb

Conversation

@gominimal-aw-bot

@gominimal-aw-bot gominimal-aw-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Routing-Key: inbox-route/I_kwDOSUhdos8AAAABK6GERQ

Setting MINIMAL_INDEX_SOURCE to an unrecognised value made min abort with a Rust panic and backtrace note, even though the underlying validation message is correct and already enumerates the valid modes. Context::download_if_available unwrapped the Result from remote_cache(), which already builds RemoteError::Config for a bad override; this propagates it via map_err so the CLI prints the clean message and exits non-zero instead of panicking. No regression test is added: reaching that call site needs a full daemon/remote-cache context and the override is a process-global env var, while the parsing that builds the message already returns Result at its source.

Verification

cargo fmt --all --check — clean
cargo clippy --workspace --locked -- -D warnings — no warnings
cargo build --workspace --locked — Finished, ok
cargo test --workspace --locked — all tests passed (0 failed)

Generated by inbox-patch ·

Note

Fix panic on invalid MINIMAL_INDEX_SOURCE in Context.download_if_available

Replaces an unwrap() on the remote cache result in Context.download_if_available with proper error propagation. A RemoteError::Config (or any other RemoteError) is now converted to Error::Other via map_err and returned to the caller instead of panicking.

Macroscope summarized 88755d5.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of remote-cache initialization failures.
    • Users now receive an error message instead of the application terminating unexpectedly.

download_if_available unwrapped the Result from remote_cache(), so an
unrecognised MINIMAL_INDEX_SOURCE value aborted with a Rust panic and
backtrace note, not a clean non-zero exit. remote_cache() already
builds RemoteError::Config for this value; propagate it via map_err
so the CLI prints the message instead of panicking.
@norrietaylor
norrietaylor marked this pull request as ready for review July 31, 2026 08:03
@norrietaylor
norrietaylor requested a review from a team as a code owner July 31, 2026 08:03

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed: scope, clobber, correctness, CI. Approving.

Scope — one file, one hunk in crates/mctx/src/lib.rs. The single removal is the .unwrap() being replaced.

No clobber — nothing else removed; no competing work in flight on this file.

Correctness — and the match arm is load-bearing, not redundant. On first read the two arms look identical, both producing Error::Other(anyhow!(...)). They are not, because rcache::Error's Display is:

impl<BE: Debug> Display for Error<BE> {
    fn fmt(&self, f) -> Result { write!(f, "{:?}", self) }
}

It Debug-formats itself. So "{other}" on a Config variant renders Config("MINIMAL_INDEX_SOURCE: unknown index source \"banana\" ...") — the variant name, quotes and escaped inner quotes, i.e. precisely the string the issue is complaining about. The RemoteError::Config(msg) => anyhow!("{msg}") arm is what unwraps the clean inner message so the user sees:

MINIMAL_INDEX_SOURCE: unknown index source "banana" (expected "auto", "pinned", "root" or "closure")

Collapsing this to a single arm would reintroduce the defect. Worth a comment in the code someday, but not worth blocking this on.

The ? replaces a panic with normal error propagation, so the binary exits non-zero with a clean message and no backtrace note — exactly what the issue asked for. The error text itself was already correct and is unchanged.

CI — 20/20 green.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

download_if_available now returns remote-cache initialization failures as Error values instead of panicking.

Changes

Remote-cache error handling

Layer / File(s) Summary
Propagate initialization errors
crates/mctx/src/lib.rs
download_if_available converts remote-cache initialization errors into Error::Other values with their messages.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Suggested reviewers: twitchyliquid64, bryan-minimal

Poem

A rabbit found an error in the cache,
And stopped the panic in a flash.
It carried the message safely through,
So callers know what failed to do.
Hop, hop—no crash anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 clearly and concisely describes the primary fix for invalid MINIMAL_INDEX_SOURCE handling.
Description check ✅ Passed The description explains the change and rationale and provides verification results; the missing checklist is non-critical.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch inbox-patch/mctx-index-source-clean-error-6859362e6b82c5bb

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

@norrietaylor
norrietaylor merged commit 1ad263c into main Jul 31, 2026
30 checks passed
@norrietaylor
norrietaylor deleted the inbox-patch/mctx-index-source-clean-error-6859362e6b82c5bb branch July 31, 2026 08:14
norrietaylor added a commit that referenced this pull request Jul 31, 2026
Both arms of the `map_err` added in #1132 produce
`Error::Other(anyhow!(...))` and read as interchangeable. They are not.

`rcache::Error`'s Display is `write!(f, "{:?}", self)` — it Debug-formats
itself — so the fallback arm renders a Config as
`Config("MINIMAL_INDEX_SOURCE: unknown index source \"banana\" ...")`,
variant name and escaped quotes included. That is exactly the string
gominimal/inbox#447 was filed about. Destructuring Config and formatting
the inner `msg` is what produces the clean user-facing message.

Collapsing this to a single arm would reintroduce the defect while
looking like a simplification. Found while reviewing #1132, where I
nearly filed that simplification myself before checking the Display impl.

Comment only; no behaviour change. `cargo check -p mctx --locked` and
`cargo fmt --all --check` both clean.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.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.

1 participant