LukeMathWalker / LukeMathWalker/pavex

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

Open
#538 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

diagnostics p-pavex-macros
Dominant language
Rust
Stars
2.1k
Forks
80
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Pavex's attribute macro implementations and the error paths used when required arguments are missing. Reproduce the route example and inspect the resulting compiler diagnostics, then verify that the attached item remains available and that the original macro error is still reported without the cascade of undefined-item errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.