Skip to content

Remove panic calls during initialization when using wazero #147

@blotus

Description

@blotus

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()).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions