Skip to content
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

Suppress context in ForwardReferenceError and MissingValueError #265

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

m-aciek
Copy link

@m-aciek m-aciek commented Oct 24, 2024

It simplifies the traceback presented to the user, not showing the library internals.

Traceback previously/now for MissingValueError:

Previously:
Traceback (most recent call last):
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 72, in from_dict
    value = get_default_value_for_field(field, field_type)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/maciej.olko/projects/dacite/dacite/dataclasses.py", line 21, in get_default_value_for_field
    raise DefaultValueNotFoundError()
dacite.dataclasses.DefaultValueNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/maciej.olko/Library/Application Support/JetBrains/PyCharm2024.2/scratches/scratch_167.py", line 11, in <module>
    from_dict(X, {"s": "test"})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 76, in from_dict
    raise MissingValueError(field.name)
dacite.exceptions.MissingValueError: missing value for field "i"

Now:

Traceback (most recent call last):
  File "/Users/maciej.olko/Library/Application Support/JetBrains/PyCharm2024.2/scratches/scratch_167.py", line 11, in <module>
    from_dict(X, {"s": "test"})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 76, in from_dict
    raise MissingValueError(field.name) from None
dacite.exceptions.MissingValueError: missing value for field "i"

Previously/now for ForwardReferenceError:

Previously:
Traceback (most recent call last):
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 51, in from_dict# couldn't really trigger this error
NameError(…)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/maciej.olko/Library/Application Support/JetBrains/PyCharm2024.2/scratches/scratch_167.py", line 11, in <module>
    from_dict(X, {"s": "test"})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 53, in from_dict
    raise ForwardReferenceError(str(error))
dacite.exceptions.ForwardReferenceError: can not resolve forward reference: 

Now:

Traceback (most recent call last):
  File "/Users/maciej.olko/Library/Application Support/JetBrains/PyCharm2024.2/scratches/scratch_167.py", line 11, in <module>
    from_dict(X, {"s": "test"})
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/Users/maciej.olko/projects/dacite/dacite/core.py", line 53, in from_dict
    raise ForwardReferenceError(str(error)) from None
dacite.exceptions.ForwardReferenceError: can not resolve forward reference: 

It simplifies the traceback presented to the user, not showing the library internals.
@m-aciek
Copy link
Author

m-aciek commented Oct 24, 2024

The linting change tested locally with:

% uvx --python 3.9 --exclude-newer=2019-12-17 pylint dacite/core.py
   Built wrapt==1.11.2
   Built lazy-object-proxy==1.4.3
Installed 7 packages in 7ms

------------------------------------
Your code has been rated at 10.00/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant