onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://developers.flow.com/cadence
Apache License 2.0
526 stars 136 forks source link

Refactor user errors in lexer from panics to error return values #3428

Open turbolent opened 1 week ago

turbolent commented 1 week ago

Issue to be solved

The lexer currently reports user errors through panics (In particular, there is currently only one user error, "token limit reached", i.e. TokenLimitReachedError).

As the lexer is used in the parser, which already previously got refactored from reporting user errors as panics in #1764, it might be surprising to users of the parser that user errors are still reported as panics in some cases.

Suggested Solution

Refactor the lexer to report user errors, such as the "token limit reached" error (TokenLimitReachedError), to be reported as an error return value, instead of a panic.