Skip to content

docs(mctx): say why the MINIMAL_INDEX_SOURCE match arms differ - #1134

Merged
norrietaylor merged 1 commit into
mainfrom
fix/mctx-index-source-arm-comment
Jul 31, 2026
Merged

docs(mctx): say why the MINIMAL_INDEX_SOURCE match arms differ#1134
norrietaylor merged 1 commit into
mainfrom
fix/mctx-index-source-arm-comment

Conversation

@norrietaylor

@norrietaylor norrietaylor commented Jul 31, 2026

Copy link
Copy Markdown
Member

Comment-only follow-up to #1132. No behaviour change.

The trap

Both arms of the map_err produce Error::Other(anyhow!(...)) and read as interchangeable:

.map_err(|e| match e {
    RemoteError::Config(msg) => Error::Other(anyhow::anyhow!("{msg}")),
    other => Error::Other(anyhow::anyhow!("{other}")),
})?

They are not. 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 the fallback arm renders a Config as Config("MINIMAL_INDEX_SOURCE: unknown index source \"banana\" ...") — variant name and escaped quotes included. That is precisely the string gominimal/inbox#447 was filed about. Destructuring Config and formatting the inner msg is what yields the clean user-facing message.

Collapsing this to a single arm would reintroduce the defect while looking like a simplification.

Why it's worth a comment

I found this reviewing #1132 and my first instinct was to file exactly that simplification. I only caught it by going and reading the Display impl in another crate. The next reader will have the same instinct with less reason to check.

Verification

  • cargo check -p mctx --locked — clean
  • cargo fmt --all -- --check — clean

🤖 Generated with Claude Code

Note

Document why MINIMAL_INDEX_SOURCE match arms in Context.download_if_available differ

Adds an inline comment in lib.rs explaining that the two map_err arms for RemoteError::Config are not interchangeable: one formats via Display (which produces Debug output), the other destructures to extract a clean inner message for user-facing output.

Macroscope summarized 71d6673.

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>
@norrietaylor
norrietaylor requested a review from a team as a code owner July 31, 2026 08:20
@norrietaylor
norrietaylor merged commit 394fa6a into main Jul 31, 2026
29 checks passed
@norrietaylor
norrietaylor deleted the fix/mctx-index-source-arm-comment branch July 31, 2026 20:42
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