Skip to content

No traceback for ValueErrors or TypeErrors when importing Things #222

@julianstirling

Description

@julianstirling

Describe the bug
As of LabThings 0.0.12. Parsing the server config and importing Things is done within a Pydantic model. However Pydantic only expects it is serialising/deserialising data and hence captures every ValueError and TypeError and raises a ValidationError without the traceback of the original error.

This means that if there is ever a TypeError or ValueError when importing a Thing the traceback is removed and an unhelpful Pydantic error is shown instead,

To Reproduce

  • Create a Value error in a Thing file that will be called at import time
  • Run labthings with this thing in the configuration

Expected behaviour
A traceback that points at the ValueError itself.

Suggested fix

While it could be possible to catch the ValueErrors or TypeErrors and raise them as a different type that Pydantic will not capture, however this is fragile to pydantic capturing changing overtime and capturing different things. It would be better to parse the configuration and serialise it with the strings. And then import the modules outside pydantic validation.

System:

  • OS: Kubuntu 24.01
  • Python version: 3.11
  • Version: 0.0.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions