-
-
Notifications
You must be signed in to change notification settings - Fork 581
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
Feature request: Add support for a second message attribute on errors which is guaranteed not to include the failing instance #1218
Comments
In general this sounds fine to me -- the main two things I think I'd want to be sure of are:
But other than the above, and a request to add tests of this property for all keywords, I'm good with it! |
I have a mix of thoughts, not all well-organized, so I'll try to summarize what I see right now.
I've found some APIs somewhat-frustrating to use when they make names for related things hard to distinguish. e.g. I really wanted to call it
This is going to take me some time to digest and make sure I understand. I'm not worried too much about it, but I haven't digested it enough to think through the implications.
I think that both of these are features which would be nice to have. # pseudocode for the new attributes
class ValidationError:
...
# a pair of (keyword, keyword-value), e.g. `("maxLength", 3)`
keyword: tuple[str, Any]
# a string unique to the keyword validation failure, e.g. "too long" for maxLength
error_category_message: str I'm just spitballing a little bit here. |
I just wanted to drop a small note, since it's been ~1 month and I haven't done anything: I still want to do this, but I'm trying to negotiate the scheduling at work so that I can do this during working hours. (I've had really limited hobby development time lately.) |
Cool, thanks for the update -- I have little doubt you won't completely disappear :D -- definitely understood on the hobby side! |
Json validation errors used to include the instance (the submitted json), the schema and the error. This changes the reporting to only print the error message without the schema and instance. This is a temporary fix until this is implemented: python-jsonschema/jsonschema#1218 It also standardizes the message for `FILE_COPY_STATUS` notifications, opting for the less verbose version.
This is a feature which I'd be very happy to work on, if it gets the ol' 👍 of approval as an idea!
(It's a case in which I could probably do FOSS work as part of my paid work allotment, rather than on personal time.)
Motivation
For context, we have a use-case at $WORK in which
jsonschema
is being used to validate data which is sourced from a mixture of locations. Some of the data is user-supplied, and some of it is sourced from config or application-owned secrets.As a result, the user who is triggering this interaction is not guaranteed to have the rights/permission to see the full body of data being passed to
jsonschema
. The application therefore cannot showValidationError.message
data, since it may contain secrets.I think the feature idea here has broader applicability -- and I don't think that the case I have at $WORK represents a great application design -- but there's my particular user story.
More generally, having some kind of message string which doesn't include the
instance
would allow applications to inspect the messages more reliably and potentially choose special behaviors for known errors. Today, this is only possible with some detailed knowledge of the error formats, and checks such aserr.message.startswith(...)
.Proposal:
ValidationError.reason
I'm proposing a new string property on error classes, which is primarily intended for
ValidationError
but may be useful in other cases (needs some evaluation). The purpose of this property is to name the error case sans the input instance. In concert with the JSON Path to the failing instance, this is nearly equivalent to the current content inmessage
, but it doesn't producestr(instance)
as part of the error message.reason
is either provided explicitly or falls back toNone
. I considered having it default tomessage
but that makes things messier for a client, which then has fewer guarantees about what might be in thereason
field.Where possible,
reason
may be used to add details which are not present in themessage
and would now be a breaking change to introduce.reason
would be documented as a concise description of the error cause which does not to contain details from the instance being evaluated.Example Changes
additionalProperties
keyword validation produces messages of the form"Additional properties are not allowed ({fields} {was|were} unexpected)"
.The
reason
field on such an error would be"Additional properties are not allowed."
.maxLength
validation produces messages of the forms"{instance} is expected to be empty"
and"{instance} is too long"
.The
reason
field on such an error would be"The value is too long. The maximum length is {maxLength}."
Note
I would be open to an alternative interpretation in which we make
reason
more closely aligned with describing the schema/spec.That could lead to terse and technical
reason
values like"additionalProperties validation failed."
or"maxLength={maxLength} exceeded."
.The above proposed changes are only where I'm leaning right now -- a slight re-encoding of
message
without the instance and potentially with other useful info.Proposed Implementation
I would make this change by first updating the core
_Error
base class to supportreason
as astr | None
field.I then "just" need to walk all of the keywords and add explicit
reason
strings for each validator, plus a test case for each.I don't think this is very complex as a change, although it is a bit tedious and laborious to add.
The text was updated successfully, but these errors were encountered: