Skip to content

[WIP/do not merge] Replace anyhow with typed errors in wit-parser#2460

Draft
PhoebeSzmucer wants to merge 2 commits intobytecodealliance:mainfrom
PhoebeSzmucer:ps/wit-parser-structured-errors
Draft

[WIP/do not merge] Replace anyhow with typed errors in wit-parser#2460
PhoebeSzmucer wants to merge 2 commits intobytecodealliance:mainfrom
PhoebeSzmucer:ps/wit-parser-structured-errors

Conversation

@PhoebeSzmucer
Copy link
Contributor

Motivation

Today, getting a file path and line number out of a parse error requires parsing the human-readable error string that anyhow produces. This is fragile: it breaks silently when error message formatting changes, and it's simply the wrong abstraction.

I want to use wit-parser in an LSP for WIT/WAC, but this change would be good for any tool that embeds wit-parser and wants to do something useful with errors.

I Know This Is Large

I'm aware this PR is bigger than ideal. The core reason it's large is that error type changes propagate through the entire call stack - there's no natural seam to split at. If this is something that we'd like to merge in some form, I can try splitting up this PR into smaller chunks - I wanted to open this draft first to start a conversation.

Global vs local spans

Currently I'm returning global Span objects as part of WitError, because existing code uses global spans almost exclusively. This makes things annoying for the consumer - they have to use the SourceMap object to map to file-local offsets. I'm considering changing the exposed spans to be resolved local spans.

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