-
Notifications
You must be signed in to change notification settings - Fork 68
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
Invalid attribute specifications being ignored; should cause compile error. #96
Comments
I think you'd need to change the generated derivation to handle all syntaxes, and to then produce a "wrong style" error or something. My hesitation with doing so is that it manual implementation of these cases would be a pain for anyone who wasn't deriving My hope is that |
I think I am running into the same issue with my I am parsing a field attribute like this. The // ...
struct Abc {
#[serde_as(as = "Vec<_>")]
field: Vec<u32>,
} If somebody mistypes the attribute as This also interacts badly with the "Unknown field" error. @TedDriggs is there any way to raise an error when this happens? |
I've figured out what's happening here, and have a draft fix for the problem. In a new minor version, Open Questions
|
If all fields of the struct are specified with An empty
Ideally the error message spells out what is what and if possible how to correct this. For an unknown field error: Unknown field: `xy`
#[serde_as(xy = Vec<_>)]`
^^
field: Vec<u32>, For a known field, but missing quotes error: Did you mean `"Vec<_>"`
#[serde_as(as = Vec<_>)]`
^^^^^^
field: Vec<u32>, |
That's a good future enhancement on top of the initial scope; for now, I've just added, "Unable to parse attribute: {syn_error_message}" so that I can get the minor version bump completed. |
`darling` pre-dates Rust support for non-meta attributes. These increase flexibility for Rust code, but mean that not `darling` does not parse all valid attributes. `darling` previously ignored these outright, creating misleading errors. This commit makes those explicit errors. Fixes #96
`darling` pre-dates Rust support for non-meta attributes. These increase flexibility for Rust code, but mean that not `darling` does not parse all valid attributes. `darling` previously ignored these outright, creating misleading errors, such as claiming all fields were missing. This commit makes unsupported attributes explicit errors. To allow for detailed diagnostic information in the future without changing the crate's public API, the parsing of `Attribute` into `MetaList` is handled in a new function that wraps `syn`'s own `parse_meta`. This commit uses that structure to include an attribute path in an example for the name-value error case; future commits could expand that function to identify places where the caller may have missed quotation marks, for example. Fixes #96
`darling` pre-dates Rust support for non-meta attributes. These increase flexibility for Rust code, but mean that not `darling` does not parse all valid attributes. `darling` previously ignored these outright, creating misleading errors, such as claiming all fields were missing. This commit makes unsupported attributes explicit errors. To allow for detailed diagnostic information in the future without changing the crate's public API, the parsing of `Attribute` into `MetaList` is handled in a new function that wraps `syn`'s own `parse_meta`. This commit uses that structure to include an attribute path in an example for the name-value error case; future commits could expand that function to identify places where the caller may have missed quotation marks, for example. Fixes #96
`darling` pre-dates Rust support for non-meta attributes. These increase flexibility for Rust code, but mean that not `darling` does not parse all valid attributes. `darling` previously ignored these outright, creating misleading errors, such as claiming all fields were missing. This commit makes unsupported attributes explicit errors. To allow for detailed diagnostic information in the future without changing the crate's public API, the parsing of `Attribute` into `MetaList` is handled in a new function that wraps `syn`'s own `parse_meta`. This commit uses that structure to include an attribute path in an example for the name-value error case; future commits could expand that function to identify places where the caller may have missed quotation marks, for example. Fixes #96
`darling` pre-dates Rust support for non-meta attributes. These increase flexibility for Rust code, but mean that not `darling` does not parse all valid attributes. `darling` previously ignored these outright, creating misleading errors, such as claiming all fields were missing. This commit makes unsupported attributes explicit errors. To allow for detailed diagnostic information in the future without changing the crate's public API, the parsing of `Attribute` into `MetaList` is handled in a new function that wraps `syn`'s own `parse_meta`. This commit uses that structure to include an attribute path in an example for the name-value error case; future commits could expand that function to identify places where the caller may have missed quotation marks, for example. Fixes #96
Absolutely excellent crate! I have been able to reduce the amount of code needed in one of my projects by a pretty drastic degree (thedodd/wither#48). Thanks for all of the excellent work here @TedDriggs!
One issue that I'm running into right now is that if a user attempts to specify a value for an enum attribute being derived, if the user does not use the syntax expected by darling, it looks like the value is either:
#[darling(default)]
is specified on the correspondingFDI
field.Missing field
error is generated ... which is going to be deceptive to users because in this case they have specified the field, it is just specified in a way that is apparently unexpected by darling (which my not be intuitive to some).To use the example which @ubolonton gave in #74 for the type
enum Name
, if the end user were to attempt to provide the attribute as a type literal, say#[pkg(name = Name::Fn)]
or#[pkg(name = Name::Str("val"))]
, doing so would trigger the behavior I've described above.The behavior I would expect would be that an error would be generated telling the user that they've specified the value for the attribute incorrectly. Any thoughts on what we should do to fix this issue?
The text was updated successfully, but these errors were encountered: