Use 'Invalid value' wording for Literal and Enum validation errors - #1010
Use 'Invalid value' wording for Literal and Enum validation errors#1010Siyet wants to merge 1 commit into
Conversation
|
The implementation seems fine, so happy to merge. However, I'm not 100% sure this is the right move.
JSON schema refers to collections of possible values as "enums", hence the use of "enum" in the error here. In Python of course these can be represented as a I don't think dropping the "enum" in the error messages makes things more confusing (and still doesn't leak python implementation details), so if you think what you have here is clearer than I'm happy with it. Just sharing context for why things were the way they were before. Up to you. |
|
Thanks for the context. The push toward "Invalid value" came down to one thing: It also gets ambiguous when both coexist: a struct with a |
This would introduce a different ambiguity though: If it refers to an |
|
Fair point, the split is arbitrary. I went through the alternatives: Mention the type in every case. The only candidate term for Literal is "literal", but that's Python-specific ( Qualify as "JSON Schema enum". Doesn't work either: msgspec errors are protocol-agnostic (same message for JSON, MsgPack, Include the field name in the message body. Already covered by the path suffix ( That leaves dropping "enum" from both, using "Invalid value" universally. This is consistent (no type qualifier in either case), doesn't leak implementation details, and matches the existing union tag errors which already use plain "Invalid value". Bigger change than the current PR since it touches Enum errors too, but it's the only option that resolves the inconsistency cleanly. I can update the branch if you and @jcrist are fine with this direction. |
1cf786a to
847c304
Compare
4d088fe to
95bb505
Compare
|
Updated the branch to use @provinzkraut this addresses the arbitrary-distinction point: the target type is no longer named in either case, and it matches the existing union tag errors which already raise plain @jcrist heads up that this also changes the real Rebased on main, tests and docs updated, full unit suite green (6368 passed). |
95bb505 to
72c42af
Compare
Merging this PR will not alter performance
Comparing Footnotes
|
|
Have we considered the word "choice"? I think that fits quite nicely and at the very least removes ambiguity. |
|
"choice" does read more precisely than "value". My hesitation is scope: to get consistent wording everywhere we'd also have to change the union tag errors (they already say
|
Closes #1009.
Validation errors for
typing.Literaltypes previously used the wordingInvalid enum value <val>, which is misleading because the user is not usingenum.Enum(see #1009).Following the discussion below, this uses a single universal wording
Invalid value <val>for bothLiteralandEnum(and the bool literals from #1004), rather than splitting the two by type. The target type is never named in the message, which resolves the "arbitrary distinction" concern and stays consistent with the existing union tag errors that already raise plainInvalid value.Before:
After:
Tests and docs updated; full unit suite passes (6368 passed).