-
Notifications
You must be signed in to change notification settings - Fork 50
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
Better handling of pydantic error msgs #546
Conversation
Personally there are two things that have bugged me about pydantic error messages:
For context it would be nice to see the offending lines/location For human readable messages I imagine it might be worth putting some work into the schema |
"Invalid YAML. A forbidden `None` value has been encountered. " | ||
) | ||
|
||
raise HTTPException(status_code=400, detail=human_readable_error) |
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.
A more scalable way to handle this would be to have a subclass of the HTTPException class that handles the translation in the constructor.
✅ Deploy Preview for kaleidoscopic-dango-0cf31d canceled.
|
I have followed @costrouc 's recommendations. Now, the validation is done in the For instance, for a spec where the name of the env is missing, and an empty dependency exists, we have the two errors like this : We need to add a fix in the UI to handle the |
@@ -564,6 +564,8 @@ async def api_post_specification( | |||
specification = schema.CondaSpecification.parse_obj(specification) | |||
except yaml.error.YAMLError: | |||
raise HTTPException(status_code=400, detail="Unable to parse. Invalid YAML") | |||
except ValueError as e: |
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.
You should use a custom exception here. Something else could raise a ValueError which wouldn't have a list in its args, and that probably shouldn't be converted to an HTTPException anyway.
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.
Done.
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.
This looks good to me, @asmeurer since you had reviewed this before, can you have another look at this and approve if applicable?
This looks fine. We'll probably want to refactor this if we start translating a lot more error messages, but with just a couple the way it's written now is fine. |
Fixes #535 (work in progress)
Description
The purpose of this PR is to present more user-friendly error messages, in case of invalid YAML specification when trying to create an env.
Pull request checklist
Did you update the documentaion (if required)?Additional information
I consider this PR as a work in progress.
pydantic error ➞ human
need to be done somewhere else ?