Skip to content

refactor(server): map Lance errors by typed variant, not Display text - #168

Merged
beinan merged 1 commit into
mainfrom
typed-error-mapping
Jul 22, 2026
Merged

refactor(server): map Lance errors by typed variant, not Display text#168
beinan merged 1 commit into
mainfrom
typed-error-mapping

Conversation

@beinan

@beinan beinan commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • AppError::from_lance took impl Display and 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).
  • Now takes lance::Error by value (re-exported as LanceError from lance-context-core) and matches typed variants: DatasetNotFound/NotFound → 404, DatasetAlreadyExists → 409, InvalidInput/SchemaMismatch → 400, else 500.
  • The one signal Lance exposes no dedicated variant for — "compaction already in progress", raised as an ArrowError::InvalidArgumentError folded into Lance's 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.

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-core clean
  • cargo fmt --all

Independent of #166 and #167.

🤖 Generated with Claude Code

`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>
@beinan
beinan merged commit d5e8b86 into main Jul 22, 2026
9 checks passed
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