Closed creatorrr closed 3 weeks ago
Hey @creatorrr, here is an example of how you can ask me to improve this pull request:
@sweep Add unit tests for the `make_exception_handler` function that cover:
1. Validation errors with different depths of nested fields
2. Common location extraction from multiple errors
3. Offending input extraction for different data structures (dict, list)
4. Edge cases where location paths don't fully exist in the input
:book: For more information on how to use Sweep, please read our documentation.
FAILED: /Users/Dell/Desktop/Julep_Workspace/julep/agents-api/.pytype/pyi/agents_api/web.pyi
/Users/Dell/miniconda3/envs/julep/bin/python -m pytype.main --disable pyi-error --imports_info /Users/Dell/Desktop/Julep_Workspace/julep/agents-api/.pytype/imports/agents_api.web.imports --module-name agents_api.web --platform linux -V 3.12 -o /Users/Dell/Desktop/Julep_Workspace/julep/agents-api/.pytype/pyi/agents_api/web.pyi --analyze-annotated --nofail --none-is-not-bool --quick --strict-none-binding /Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:68:28: error: in _handler: unsupported operand type(s) for item retrieval: 'error: Exception' and ''loc': str' [unsupported-operands]
No attribute '__getitem__' on 'error: Exception'
max_depth = max(len(error["loc"]) for error in errors)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:69:56: error: in _handler: unsupported operand type(s) for item retrieval: 'error: Exception' and ''loc': str' [unsupported-operands]
No attribute '__getitem__' on 'error: Exception'
errors = [error for error in errors if len(error["loc"]) == max_depth]
~~~~~~~~~~~~
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:72:24: error: in _handler: unsupported operand type(s) for item retrieval: 'Exception' and ''loc': str' [unsupported-operands]
No attribute '__getitem__' on 'Exception'
location = errors[0]["loc"]
~~~~~~~~~~~~~~~~
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:74:43: error: in _handler: unsupported operand type(s) for item retrieval: 'error: Exception' and ''loc': str' [unsupported-operands]
No attribute '__getitem__' on 'error: Exception'
for a, b in zip(location, error["loc"]):
~~~~~~~~~~~~
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:83:31: error: in _handler: No attribute 'body' on Exception [attribute-error]
offending_input = exc.body
~~~~~~~~
/Users/Dell/Desktop/Julep_Workspace/julep/agents-api/agents_api/web.py:100:23: error: in _handler: unsupported operand type(s) for item retrieval: 'error: Exception' and ''msg': str' [unsupported-operands]
No attribute '__getitem__' on 'error: Exception'
errors = [error["msg"] for error in errors]
~~~~~~~~~~~~
For more details, see https://google.github.io/pytype/errors.html
ninja: build stopped: cannot make progress due to previous errors.
Leaving directory '.pytype'
Error: Sequence aborted after failed subtask 'typecheck'
Previously, the error messages on validation errors were horrendous. The following input would have yielded a huge, unreadable mess as an error message. This happened because we make heavy use of union types and pydantic tries to unify each type and collects the error for each one of them. Fixed by returning only the deepest matching exceptions.
Input
New error format
Previous error format