-
Notifications
You must be signed in to change notification settings - Fork 793
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
Improve error prioritisation and messages #3009
Conversation
…fication. Relevant as sometimes only one is shown in the resulting error message
…lement before passing to SchemaValidationError to allow for better error messages to be created
…lready happens in validate_jsonschema
…pect.cleandoc. This makes it easier to work on the error messages
…it should be as this depends on the frontend
…ere as we upgrade to 5.7 anyway before a release
PR is ready for review :) I'll do another review myself this weekend but wanted to already put this up to get your inputs in case you find the time, especially as we might still get it into version 5 which I think would be great! |
…hanges here as we upgrade to 5.7 anyway before a release" This reverts commit 09805a3.
Tests will fail until vega/schema#8 is resolved. |
Wohoo! Exciting to see this ready for review 🎉 Thanks for all your hard work on the PR, it looks really awesome at first glance =)
I agree, and I think even getting this into 5 RC2 would be a good goal. It seems like we might want to wait for vega/schema#8 before releasing RC 2 anyways? I will try to review as soon as possible, but a deeper look will probably have to wait until end/middle of next week for me unfortunately. But I can say already that I like all the approaches taken here, and it is interesting that we know show more than just one Error. I agree with you that the formatting is important for this not to be confusing. To me the indented example you showed above is notably clearer than the other one. Maybe even tweaked to explicitly mention on the first line that there are multiple errors?
Without indendation, maybe three
I am OK with either of those two approaches; I think the indentation is easier to quickly scan for the two errors, so I favor that a bit (unless there are any width issues width only indenting for multiple errors, but I can't think of why that would be the case). I also slightly favor having the One more thought, do you think it makes sense to have a max on the number of errors that can be displayed? I am thinking something like 3-5, because above that it might be hard to parse/scroll, and also to guard against some possible odd scenario when 20+ errors are shown (not sure if this possible and it definitely doesn't seem likely but maybe it is still a good idea to have an upper limit in place as a safeguard). What do you think? |
Happy to hear! :) And thank you for the first feedback. I fully agree with all your points and implemented them. I went for the indentation as I also think it's more readable then some solution with dividers. At most 3 errors are now shown. |
…a. Changes are not relevant as we upgrade to 5.7 anyway. They happened as part of resolving vega/schema vega#8
Tests are failing because altair_viewer no longer supports VL 5.6 so we'll first need to merge #3022 once it's ready. |
(did a quick check if this PR pass the bump to VL5.7.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks amazing and will be a huge help for all Altair users, thank you so much for tackling this @binste ! And sorry for taking some time to get to it. I have a few minor comments, but I also think this is good to go as is, so feel free to update/resolve as you see fir and we can merge it after. Although all the changes here seems to make sense to me and the tests are encompassing, I think it is important that we start running this ourselves and get it into the next RC, so that we get the chance to stumble upon error cases that are difficult to anticipate ahead of time.
No worries at all and thank you for the review and the feedback! I addressed your comments and it's ready to be merged from my side. Looking forward to RC2! |
Great, thank you again! Merging this! |
Background
Error messages in Altair are mostly generated based on the validation of the chart specification against the Vega-Lite schema. This validation is performed by the
jsonschema
package. It's not straight forward to generate helpful error messages out of these specs and Altair 5 rc1 already contains various improvements over Altair 4 in this regard. One improvement was the replacement of the previous 'deep validation' approach with the error hierarchy returned byjsonschema
, see #2842. The main benefits over 'deep validation' were that it solved some error messages pointing to parts of the specifications which are actually correct, and the second one was that we can use the error hierarchy to craft more helpful error messages as we now have structured information on all the errors in the chart specification. This last benefit was already somewhat used in #2957.This PR aims to further use the error hierarchy to improve error messages. It resolves #2915, resolves #2873 and partially addresses #2913.
Suggested approach
See #2842 for a description of how the validation works in general. This PR keeps the separation between
validate_jsonschema
andSchemaValidationError
the same so that:validate_jsonschema
: Validates the chart spec against a JSON schema and prioritizes and prepares the relevant error messagesSchemaValidationError
: Creates a more user friendly error message out of the errors fromvalidate_jsonschema
I tried to document the changes in the code and added more examples to
test_schemapi
so you can see how the errors look. However, let me know if I should write up a more detailed walkthrough. Below, I just show some examples:Aggregate multiple error messages which are about the same error in the chart specification (#2873)
If it would be just one
one of
line or only types then it is shown on the same line and not as a list item:Prefer errors from "deeper levels" of the schema (#2915)
Fixes both examples from #2915 for layered and faceted charts. See that issue for more details. This part happens in
schemapi.py:_subset_to_most_specific_json_paths
. For thelayer
example in #2915 it keeps the error for the tooltip as the other error has a json path'$.layer[0]'
and the tooltip error is at'$.layer[0].encoding.tooltip'
.Show all errors in the chart specification
In case a chart spec has multiple errors, so far we only showed one and as soon as that one was resolved the other showed up. As a user, I'd prefer to see all at once, else I sometimes think the change I did to resolve one error caused another error although the two are unrelated:
Open questions/todos
What I think could be tackled in separate PRs:
'null'
withNone
, can be tackled in a separate PR, see Show python types instead of javascript types in error messages #2914.alt.datum
andalt.value
generates incorrect error messages #2913 is still not optimal as it now saysX has no parameter named 'wrong_argument'
although it should say something about'wrong_argument' is not a valid parameter for 'datum' in this context
. The previous error messages was more confusing so I think this is an improvement and would suggest to keepalt.datum
andalt.value
generates incorrect error messages #2913 open