Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove panic calls during initialization when using wazero #147

Open
blotus opened this issue Sep 13, 2024 · 0 comments
Open

Remove panic calls during initialization when using wazero #147

blotus opened this issue Sep 13, 2024 · 0 comments

Comments

@blotus
Copy link
Contributor

blotus commented Sep 13, 2024

Following up the discussion in #144, I'd like to propose an alternative way to handle errors during wazero initialization.

Currently, go-re2 just calls panic in the init() function, which makes it quite hard in some (rare) situations to get any information about the error that occured.

The idea would be store the initialization error at the package level, and just returning in init() instead of calling panic().

The state of the error would then be checked in each entrypoint method in the go-re2 package, and returned to the user if something went wrong during the initialization.

The entrypoints are:

  • Compile
  • MustCompile
  • CompilePOSIX
  • MustCompilePOSIX
  • MatchString
  • Match
  • QuoteMeta

The only function that does not return an error/panics is QuoteMeta, but it's just a wrapper around regexp.QuoteMeta, so we could just ignore any initialization error in it.

For the others, the error would be handled the same way they currently handle errors (either returning it or calling panic()).

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

No branches or pull requests

1 participant