Skip to content

Commit f09e76e

Browse files
committed
add format_version error for future format versions if other errors occur
1 parent db1b940 commit f09e76e

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

bioimageio/spec/io_.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from types import ModuleType
1313
from typing import Dict, IO, Optional, Sequence, Tuple, Union
1414

15-
from marshmallow import missing
15+
from marshmallow import ValidationError, missing
1616
from packaging.version import Version
1717

1818
from bioimageio.spec.shared import RDF_NAMES, raw_nodes, resolve_rdf_source, resolve_rdf_source_and_type, resolve_source
@@ -199,7 +199,8 @@ def load_raw_resource_description(
199199
# => 'format_version' may be invalid or the issue lies with 'type_'...
200200
raise e
201201

202-
if odv and Version(sub_spec.format_version) < odv:
202+
downgrade_format_version = odv and Version(sub_spec.format_version) < odv
203+
if downgrade_format_version:
203204
warnings.warn(
204205
f"Loading future {type_} format version {original_data_version} as (latest known) "
205206
f"{sub_spec.format_version}."
@@ -218,7 +219,16 @@ def load_raw_resource_description(
218219
schema: SharedBioImageIOSchema = getattr(sub_spec.schema, class_name)()
219220

220221
data = sub_spec.converters.maybe_convert(data)
221-
raw_rd = schema.load(data)
222+
try:
223+
raw_rd = schema.load(data)
224+
except ValidationError as e:
225+
if downgrade_format_version:
226+
e.messages["format_version"] = (
227+
f"Other errors may be caused by a possibly incompatible future format version {original_data_version} "
228+
f"treated as {sub_spec.format_version}."
229+
)
230+
231+
raise e
222232

223233
if isinstance(root, pathlib.Path):
224234
root = root.resolve()

0 commit comments

Comments
 (0)