pavex icon indicating copy to clipboard operation
pavex copied to clipboard

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

Open LukeMathWalker opened this issue 5 months ago • 4 comments

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.

LukeMathWalker avatar Sep 10 '25 14:09 LukeMathWalker