chore(compiler): Prefer option over exception Not_found where possible in compiler helpers.#2349
Open
spotandjake wants to merge 1 commit intograin-lang:mainfrom
Open
Conversation
I've noticed that a lot of the crashes in the lsp and compiler tend to relate back to `Not_found` exceptions which bubble up from the `Env` and other helper functions. This pr does some refactoring to begin moving us over to using options rather than exceptions which helps to keep error handling more localized and make missing id's more clear. I haven't fully refactored everything as this pr is already getting rather large and I wanted to get opinions on this change before going any further. This probably makes sense to merge after we merge wasm-gc to make the rebasing of that pr easier. If we don't like this change i'm happy to close this pr as well. Longer term I would like to have all of our helper functions return either options or result types and `raise` only to be used for actual user facing compiler errors.
ospencer
reviewed
Feb 8, 2026
Member
ospencer
left a comment
There was a problem hiding this comment.
Overall, this looks really good. My main piece of feedback is that for constructs that we define, we drop the _opt ending. So long as we consistently return options, that ending is redundant. (Plus, the _opt to me implies that there's a version that will raise instead, and we shouldn't have those.)
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.
I've noticed that a lot of the crashes in the lsp and compiler tend to relate back to
Not_foundexceptions which bubble up from theEnvand other helper functions.This pr does some refactoring to begin moving us over to using options rather than exceptions which helps to keep error handling more localized and make missing id's more clear.
I haven't fully refactored everything as this pr is already getting rather large and I wanted to get opinions on this change before going any further.
This probably makes sense to merge after we merge wasm-gc to make the rebasing of that pr easier. If we don't like this change i'm happy to close this pr as well.
Longer term I would like to have all of our helper functions return either options or result types and
raiseonly to be used for actual user facing compiler errors.