-
-
Notifications
You must be signed in to change notification settings - Fork 592
Make json look prettier in errors #243
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
Comments
I'll follow up with a longer reply when I get a sec (sorry) -- the general answer I've had for this question has been "error messages are for developers, not end users" -- showing reprs is important for developers because reprs are what's generally informative to know what's going on. That being said, I think it's come up to parametrize the actual thing used here because of other reasons (truncating long instances via Also FWIW it'd be less than tedious I think depending on exactly what you're after, but yes a slight bit of copy pasting from I can follow up with some more, definitely worth discussing. |
The problem with this is that the validators in Currently now I hacked in some regex that removed the I'm curious about your idea to parameterize stuff and would love to hear more! |
This comment has been minimized.
This comment has been minimized.
On similar note, one thing that annoyed me a bit was that the validation error didn't tell you exactly where in the json doc the error occurred. I wrote a small utility function which fixed that (see https://github.com/ccpgames/jsonschema-errorprinter). This is how the example error from the readme file would look: >>> print check_json({"name" : "Eggs", "price" : "Invalid"}, schema)
Schema check failed for '?'
Error in line 2:
1: {
2: >>> "price": "Invalid",
3: "name": "Eggs"
4: }
'Invalid' is not of type 'number'
Failed validating 'type' in schema['properties']['price']:
{'type': 'number'}
On instance['price']:
'Invalid' |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@mattig That's really cool, and it nicely solves what I was getting at in my above comment. Wish I'd known of it at the time. I no longer work at the job where my above comment was raised (time flies, haha), but they're open sourcey, so if I'm feeling ambitious in my free time I may add your functionality to their stack. @Julian I am curious about your vision for the scope of |
@ramanshah I forget if I've seen that library before, but from a quick 10 second read it's quite minimal in what it changes. I'm all for making the tracebacks as useful as possible to developers yeah, although there's certainly 2 schools of thought on how long tracebacks ought to be, and so I try to strike a bit of a balance. In theory though, if it's liked enough, that sort of thing could go here. What I don't want to get into in this library is supporting messaging for end-users, because it's a can of worms. I can provide all the hooks necessary to create such a thing, and I believe all those hooks should exist already (would love to create any that don't, so if any are missing please file an issue), but I don't think that error messages emitted by jsonschema should be directly rendered for non-developer users at the moment -- jsonschema needs to pick one of the two, developers or end-users, and it currently picks the former. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
For more examples here, see the schema+instance in #350 which produces a ridiculous output. The problem there is more about indentation, but let's be sure we cover it. |
…dos desde python Ver python-jsonschema/jsonschema#243 refs:#87
8982b0b Merge pull request #243 from gregsdennis/master 432eab6 added draft-03 version f55b4c2 Added test for additional properties looking in applicator keywords git-subtree-dir: json git-subtree-split: 8982b0ba6d721b09d91ebbf2414fdf443e4740b4
Schemas, particularly longer ones, are often written intentionally with their keywords in some specific human-understandable order. pprint, which we currently use (for better or worse) for rendering schemas and instances, supports *not* sorting dicts now that they maintain their insertion order. So we now pass that argument, and thereby preserve the order the schema was written in. Refs: #243
I'm not sure if this is a real issue or not, but something that bothered me is that validation errors use
"%r"
as a format string which causes your json to look pretty ugly in the error message with all strings looking like{u'key':u'value'}
instead of{"key":"value"}
.In my json API when I return an error it might be confusing for the developer using my API that there's suddenly and
u
in a string because that's not valid JSON.Of course I could build a custom error message from all the errors I get, but that would be a bit tedious. Would it be something to consider to print the schemas and validated data as json strings instead of python dicts in error messages?
Perhaps it's something worth discussing.
The text was updated successfully, but these errors were encountered: