diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d09039a6..808773404 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Speed up validating annotations with user fields ([#1078](../../pull/1078)) - Speed up validating annotation colors ([#1080](../../pull/1080)) - Support more complex bands from the test source ([#1082](../../pull/1082)) +- Improve error thrown for invalid schema with multi source ([#1083](../../pull/1083)) ### Bug Fixes - The cache could reuse a class inappropriately ([#1070](../../pull/1070)) diff --git a/sources/multi/large_image_source_multi/__init__.py b/sources/multi/large_image_source_multi/__init__.py index cf92e65fb..013a2fcdf 100644 --- a/sources/multi/large_image_source_multi/__init__.py +++ b/sources/multi/large_image_source_multi/__init__.py @@ -423,7 +423,10 @@ def __init__(self, path, **kwargs): self._info = yaml.safe_load(fptr) except (json.JSONDecodeError, yaml.YAMLError, UnicodeDecodeError): raise TileSourceError('File cannot be opened via multi-source reader.') - self._validator.validate(self._info) + try: + self._validator.validate(self._info) + except jsonschema.ValidationError: + raise TileSourceError('File cannot be validated via multi-source reader.') self._basePath = Path(self._largeImagePath).parent self._basePath /= Path(self._info.get('basePath', '.')) for axis in self._info.get('axes', []): diff --git a/test/test_source_multi.py b/test/test_source_multi.py index ae8d33b7e..701b151a3 100644 --- a/test/test_source_multi.py +++ b/test/test_source_multi.py @@ -126,6 +126,15 @@ def testTilesFromMultiString(): large_image_source_multi.open('invalid' + sourceString) +def testTilesFromNonschemaMultiString(): + sourceString = json.dumps({'sources': [{ + 'sourceName': 'test', 'path': '__none__', + 'notAKnownKey': 'X', + 'params': {'sizeX': 10000, 'sizeY': 10000}}]}) + with pytest.raises(large_image.exceptions.TileSourceError): + large_image_source_multi.open(sourceString) + + @pytest.mark.skipif(sys.version_info < (3, 7), reason='requires python >= 3.7 for a sub-source') def testInternalMetadata(multiSourceImagePath): imagePath = multiSourceImagePath