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

Fix verify_regex proc macro's error handling #438

Merged
merged 1 commit into from
Jun 30, 2022

Conversation

edmorley
Copy link
Member

@edmorley edmorley commented Jun 29, 2022

Previously if an error was encountered whilst parsing the regex, a confusing internal macro error was emitted (see #437 for output).

Now the actual regex error is output, eg:

error: Could not compile regular expression: Opening parenthesis without closing parenthesis
  --> examples/ruby-sample/src/main.rs:40:47
   |
40 |         let ruby_layer = context.handle_layer(layer_name!("ruby"), RubyLayer)?;
   |                                               ^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `layer_name` (in Nightly builds, run with -Z macro-backtrace for more info)

See:
https://docs.rs/syn/latest/syn/struct.Error.html
https://stackoverflow.com/a/54394014

Fixes #437.
GUS-W-11375177.

Previously if an error was encountered whilst parsing the regex, a
confusing internal macro error was emitted (see #437 for output).

Now the actual regex error is output, eg:

```
error: Could not compile regular expression: Opening parenthesis without closing parenthesis
  --> examples/ruby-sample/src/main.rs:40:47
   |
40 |         let ruby_layer = context.handle_layer(layer_name!("ruby"), RubyLayer)?;
   |                                               ^^^^^^^^^^^^^^^^^^^
   |
   = note: this error originates in the macro `layer_name` (in Nightly builds, run with -Z macro-backtrace for more info)
```

See:
https://docs.rs/syn/latest/syn/struct.Error.html
https://stackoverflow.com/a/54394014

Fixes #437.
@edmorley edmorley added bug Something isn't working libcnb-proc-macros labels Jun 29, 2022
@edmorley edmorley self-assigned this Jun 29, 2022
@edmorley edmorley marked this pull request as ready for review June 29, 2022 21:05
@edmorley edmorley requested a review from a team as a code owner June 29, 2022 21:05
@Malax
Copy link
Member

Malax commented Jun 30, 2022

Nice find and fix! 👍🏻

@edmorley edmorley merged commit 7fe9f80 into main Jun 30, 2022
@edmorley edmorley deleted the edmorley/fix-verify-regex-errors branch June 30, 2022 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libcnb-proc-macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

verify_regex macro gives parsing error when regex could not be compiled
2 participants