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

scylla-macros: report errors as compile errors, not panics #818

Merged
merged 1 commit into from Oct 5, 2023

Commits on Sep 28, 2023

  1. scylla-macros: report errors as compile errors, not panics

    Our current procedural macros handle errors by panicking. This leads to
    compilation errors which inform the user about that fact first, and then
    explain the real issue in the "help" part:
    
    ```
    error: proc-macro derive panicked
     --> examples/user-defined-type.rs:6:10
      |
    6 | #[derive(FromUserType)]
      |          ^^^^^^^^^^^^
      |
      = help: message: derive(FromUserType) works only on structs!
    ```
    
    This commit gets rid of `.expect()` and `panic()` calls. Instead, errors
    are now propagated via `Result<T, syn::Error>` and properly converted to
    a compilation error at the end. This approach results in nicer error
    messages and allows to attach the message to a particular part of the
    original code that could cause the problem.
    
    After the changes, error messages look like this:
    
    ```
    error: derive(FromUserType) works only for structs with named fields
     --> examples/user-defined-type.rs:7:1
      |
    7 | enum Foo {
      | ^^^^
    ```
    piodul committed Sep 28, 2023
    Configuration menu
    Copy the full SHA
    89a071c View commit details
    Browse the repository at this point in the history