Skip to content

Make GlobalConfigValidation errors more readable #1751

Description

@perolavsvendsen

When there are issues with global config, fmu-dataio will throw ValidationError. This produces a pretty large stack trace. For most users, this is tricky to understand and parse.

E.g. when required field "model" is missing, the error will be on the form

Traceback (most recent call last):
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/_global_config.py", line 61, in build_global_configuration
    return GlobalConfiguration.model_validate(config_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(redacted)/lib/python3.11/site-packages/pydantic/main.py", line 732, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 3 validation errors for GlobalConfiguration
access
  Field required [type=missing, input_value={'global': {'model': {'na...OE', 'ISACTIVE_IDX': 1}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.13/v/missing
masterdata
  Field required [type=missing, input_value={'global': {'model': {'na...OE', 'ISACTIVE_IDX': 1}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.13/v/missing
model
  Field required [type=missing, input_value={'global': {'model': {'na...OE', 'ISACTIVE_IDX': 1}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.13/v/missing
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  Python script, line 3
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/export/rms/structure_depth_surfaces.py", line 123, in export_structure_depth_surfaces
    return _ExportStructureDepthSurfaces(project, horizon_folder).export()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/export/rms/structure_depth_surfaces.py", line 32, in __init__
    super().__init__()
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/export/_base.py", line 21, in __init__
    self._config = load_global_config(standard_result=True)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/_global_config.py", line 210, in load_global_config
    return load_global_config_from_global_variables(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/_global_config.py", line 103, in load_global_config_from_global_variables
    return build_global_configuration(config_dict, standard_result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "(redacted)/lib/python3.11/site-packages/fmu/dataio/_global_config.py", line 81, in build_global_configuration
    raise ValidationError("\n\n".join(parts)) from err
fmu.dataio.exceptions.ValidationError: "The global configuration is invalid.\n\nExporting standard results requires a valid global configuration.\n\nFollow the 'Getting started' steps to do the necessary setup:\n[https://fmu-dataio.readthedocs.io/en/latest/getting_started.html\n\nDetailed](https://fmu-dataio.readthedocs.io/en/latest/getting_started.html/n/nDetailed) information:\n3 validation errors for GlobalConfiguration\naccess\n  Field required [type=missing, input_value={'global': {'model': {'na...OE', '(redacted)': 1}}, input_type=dict]\n    For further information visit [https://errors.pydantic.dev/2.13/v/missing\nmasterdata\n](https://errors.pydantic.dev/2.13/v/missing/nmasterdata/n)  Field required [type=missing, input_value={'global': {'model': {'na...OE', '(redacted)': 1}}, input_type=dict]\n    For further information visit [https://errors.pydantic.dev/2.13/v/missing\nmodel\n](https://errors.pydantic.dev/2.13/v/missing/nmodel/n)  Field required [type=missing, input_value={'global': {'model': {'na...OE', '(redacted)': 1}}, input_type=dict]\n    For further information visit [https://errors.pydantic.dev/2.13/v/missing"](https://errors.pydantic.dev/2.13/v/missing%22)

I observe that some start reading from the top, most (myself included) start reading from the base. To find the actual relevant part, and understand it, require some knowledge.

All the information is there, but it is a bit obscured by the rest of the trace.

Is it possible to detect the key information and present this? This is an expected error I guess, which can be caught and presented in a more readable format?

E.g. something like

[ERROR] Global configuration is not valid.

The following entries are required, but missing:
  masterdata
  access
  model

For further information visit...

Do we have to show full stack trace? Or can this be logged somewhere else? Can we control verbosity in a good way?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions