refactor(server): map Lance errors by typed variant, not Display text - #168
Merged
Conversation
`AppError::from_lance` took `impl Display` and string-matched the
rendered message ("not found", "Invalid", ...), which is brittle and
over-broad (e.g. any message containing "Invalid" became a 400). Take
`lance::Error` by value (re-exported as `LanceError` from core) and match
its typed variants: DatasetNotFound/NotFound -> 404,
DatasetAlreadyExists -> 409, InvalidInput/SchemaMismatch -> 400.
The one signal Lance has no dedicated variant for — "compaction already
in progress", raised as an ArrowError folded into the generic `Arrow`
variant — is still matched by text, but checked up front so it keeps
mapping to 409 COMPACTION_IN_PROGRESS. All call sites already passed
`lance::Error`, so no caller changes were needed.
Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AppError::from_lancetookimpl Displayand string-matched the rendered message ("not found","Invalid","DatasetNotFound"). That is brittle (breaks on any Display wording change) and over-broad (any message containing"Invalid"— e.g.InvalidTableLocation,InvalidRef— became a 400).lance::Errorby value (re-exported asLanceErrorfromlance-context-core) and matches typed variants:DatasetNotFound/NotFound→ 404,DatasetAlreadyExists→ 409,InvalidInput/SchemaMismatch→ 400, else 500.ArrowError::InvalidArgumentErrorfolded into Lance's genericArrowvariant — is still matched by text, but checked up front so it keeps mapping to 409COMPACTION_IN_PROGRESS.lance::Error, so no caller changes were needed.Test plan
cargo test -p lance-context-server error::(typed-variant mapping + Arrow-wrapped compaction case)cargo clippy -p lance-context-server -p lance-context-corecleancargo fmt --allIndependent of #166 and #167.
🤖 Generated with Claude Code