Skip to content

UX improved error message idea: List valid attribute keys on error #325

@schneems

Description

@schneems

First of, thanks for the crate. Lots of great stuff here. A co-worker suggested I take a look as I've been hand-rolling a lot of proc-macros recently.

One of the things I've done is to list out all possible attribute keys on error, implementation and another.

You can see the output of these implementations in this test.

Hand-rolled output:

Unknown cache_diff attribute: `unknown`. Must be one of `rename`, `display`, `ignore`

Versus darling::FromDeriveInput output:

Unknown field: `unknown`

Through the suggestions feature I see errors like:

>Unknown field: `custommm`. Did you mean `custom`?`

So I'm guessing that there's a minimum threshold for the similarity score. When that's not met, instead of printing nothing, what if we printed all known keywords? Perhaps some people want to limit the number shown, it could be configurable, perhaps something like #[darling(suggest(max_fallback = 8))] to limit the number of attributes show to 8. Then (like the Rust compiler) it could emit ... and N more. To indicate the list isn't exhaustive.

Alternatives: Always list out all valid on failure, even when there's a "did you mean" match.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions