Added diagnostic attributes to improve error messages #1412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an attempt to improve error messages for newcomers.
In the scenario when you forget to derive
ToSchema
the current error message can be a bit overwhelming if you are new to Rust.The current compiler error is
This is a lot.
I think the compiler trying to recommend other types that impl
ToSchema
is almost always unhelpful.It's probably quite rare that someone is passing
Foo
to the utoipa macro when they should passing a primitive.Thus I added:
diagnostic::on_unimplemented
onToSchema
with the recommendation to deriveToSchema
diagnostic::do_not_recommend
on all of the implmentors ofToSchema
,ParitialSchema
, andComposeSchema
.With the changes the compiler error is:
I still find the mention of
PartialSchema
unneeded but I think there is a way to avoid that.Regardless, I think this is an improvement.
Note on MSRV: Diagnostic attributes were stabilized in Rust 1.78 and
do_not_recommend
was added in Rust 1.85.However the diagnostic namespace allows forward compatibility by ignoring unknown attributes. So the MSRV should only need to be raised to 1.78.