epics-containers / pvi

EPICS PV Interface described in YAML
https://epics-containers.github.io/pvi
Apache License 2.0
4 stars 3 forks source link

Include YAML path in validation errors #108

Closed GDYendell closed 7 months ago

GDYendell commented 7 months ago

This prints the file path with pydantic ValidationErrors raised when trying to create a Device instance from a dictionary loaded from a YAML file.

Fixes #99

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 89.65%. Comparing base (50cb1be) to head (62609fe).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #108 +/- ## ========================================== + Coverage 89.62% 89.65% +0.02% ========================================== Files 23 23 Lines 1398 1402 +4 ========================================== + Hits 1253 1257 +4 Misses 145 145 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

gilesknap commented 7 months ago

I wouldn't say that re-constructing the validation error was super tidy. So I have a slight preference for catch - print - re-raise.

GDYendell commented 7 months ago

Yeah I think this is just as good and less code:

+ ibek runtime generate /epics/ioc/config/ioc.yaml /epics/ibek-defs/ADCore.ibek.support.yaml /epics/ibek-defs/ADSimDetector.ibek.support.yaml /epics/ibek-defs/asyn.ibek.support.yaml /epics/ibek-defs/autosave.ibek.support.yaml /epics/ibek-defs/epics.ibek.support.yaml /epics/ibek-defs/iocStats.ibek.support.yaml

Failed to validate `/epics/pvi-defs/asynNDArrayDriver.pvi.device.yaml` as Device:

Traceback (most recent call last):

  File "/venv/bin/ibek", line 8, in <module>
    sys.exit(cli())

  File "/venv/lib/python3.10/site-packages/ibek/runtime_cmds/commands.py", line 47, in generate
    pvi_index_entries, pvi_databases = generate_pvi(ioc_instance)

  File "/venv/lib/python3.10/site-packages/ibek/runtime_cmds/commands.py", line 91, in generate_pvi
    device.deserialize_parents([GLOBALS.PVI_DEFS])

  File "/workspaces/pvi/src/pvi/device.py", line 483, in deserialize_parents
    parent_parameters = find_components(self.parent, yaml_paths)

  File "/workspaces/pvi/src/pvi/device.py", line 526, in find_components
    list(find_components(device.parent, yaml_paths))

  File "/workspaces/pvi/src/pvi/device.py", line 523, in find_components
    device = Device.deserialize(device_yaml)

  File "/workspaces/pvi/src/pvi/device.py", line 468, in deserialize
    return cls(**serialized)

  File "/venv/lib/python3.10/site-packages/pydantic/main.py", line 171, in __init__
    self.__pydantic_validator__.validate_python(data, self_instance=self)

pydantic_core._pydantic_core.ValidationError: 2 validation errors for Device
children.0.Group.children.3.SignalR.read_pv
  Field required [type=missing, input_value={'name': 'SerialNumber', ...RBV', 'read_widget': {}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.6/v/missing
children.0.Group.children.3.SignalR.red_pv
  Extra inputs are not permitted [type=extra_forbidden, input_value='$(P)$(R)SerialNumber_RBV', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden