Skip to content

feat: Improve user-facing compiler errors when Pavex attribute macros return an error #538

@LukeMathWalker

Description

@LukeMathWalker

Context

Attribute macros replace the item they were attached to. This is not the same behaviour you get with derive macros: in that case, the decorated item is left untouched, no matter what the macro expands to.

Issue

Let's consider a simple route definition:

#[pavex::get]
pub fn my_route() -> pavex::Response {
    // [...]
}

#[pavex::get] will emit an error, since no path argument was provided.
Since it didn't expand successfully, no code will be emitted. As a consequence, there will be no definition for my_route in the crate that gets compiled by cargo.
Every single reference to my_route anywhere else in the codebase (e.g. in a unit test) will trigger an "undefined item" error from rustc.

Desired behaviour

Pavex attribute macros should always re-emit the item they were attached to in case of error, thus reducing noise for the end-user.
Otherwise, our own error gets lost in the flood of artificial issues that ended up causing by "swallowing" the item definition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    diagnosticsImprovement or issue with Pavex's CLI diagnostics.p-pavex-macros

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions