From 16f9e50edc5fae14e80a07329d875149bae490c7 Mon Sep 17 00:00:00 2001 From: Isabella do Amaral Date: Fri, 25 Oct 2024 10:29:20 -0300 Subject: [PATCH] improve edge-case error message Signed-off-by: Isabella do Amaral --- omlmd/helpers.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/omlmd/helpers.py b/omlmd/helpers.py index ec3b720..faa481e 100644 --- a/omlmd/helpers.py +++ b/omlmd/helpers.py @@ -6,6 +6,7 @@ from collections.abc import Sequence from dataclasses import dataclass, field from pathlib import Path +from textwrap import dedent from .constants import ( FILENAME_METADATA_JSON, @@ -57,10 +58,18 @@ def push( logger.debug(f"{json_meta}, {yaml_meta}") with open(json_meta, "r") as f: model_metadata = ModelMetadata.from_json(f.read()) - elif (p := json_meta).exists() or (p := yaml_meta).exists(): - raise RuntimeError( - f"File '{p}' already exists. Aborting TODO: demonstrator." - ) + elif meta_files := [f for f in (json_meta, yaml_meta) if f.exists()]: + file_list = "\n".join([str(f) for f in meta_files]) + err = dedent(f""" +OMLMD intermediate metadata files found at '{path.parent}'. +Cannot resolve with conflicting keyword args: {kwargs}. +You can reuse the existing metadata by omitting any keywords. +If that was NOT intended, please REMOVE the files under +{file_list} +from your environment before re-running. + +Note for advanced users: if merging keys with existing metadata is desired, you should create a Feature Request upstream: https://github.com/containers/omlmd""") + raise RuntimeError(err) else: model_metadata = ModelMetadata.from_dict(kwargs) json_meta.write_text(model_metadata.to_json())