Skip to content

Commit

Permalink
ENH: Graceful metadata validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JB Lovland committed Feb 2, 2024
1 parent 3c6fad0 commit fbca393
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/fmu/dataio/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@
from copy import deepcopy
from datetime import datetime
from pathlib import Path
from pprint import pformat
from typing import Any, Final, Literal

import pandas as pd
import xtgeo
import yaml
from pydantic import ValidationError

from fmu.config import utilities as ut

from . import _design_kw
from ._logging import null_logger
from .datastructure.meta import meta

logger: Final = null_logger(__name__)

Expand Down Expand Up @@ -82,6 +85,15 @@ def export_metadata_file(
"Export of metadata was requested, but no metadata are present."
)

try:
meta.Root.model_validate(metadata)
except ValidationError as e:
logger.warning(
"Unable to validate metadata(%s)",
pformat(metadata, indent=2),
exc_info=e,
)

if savefmt == "yaml":
with open(file, "w", encoding="utf8") as stream:
stream.write(
Expand Down

0 comments on commit fbca393

Please sign in to comment.