From b099714c75d21ec15670688040a984c91f452609 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 5 Oct 2023 15:03:00 +0200 Subject: [PATCH] add asset list in error message --- CHANGES.md | 4 ++++ rio_tiler/io/base.py | 34 +++++++++++++++++----------------- rio_tiler/io/stac.py | 8 ++++++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index ab1f6263..de2eb99f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,4 +1,8 @@ +# 6.2.2 (2023-10-05) + +* add list of assets in `InvalidAssetName` message in `STACReader` + # 6.2.1 (2023-09-28) * allow GeoJSON `Feature` in `ImageData.get_coverage_array` method diff --git a/rio_tiler/io/base.py b/rio_tiler/io/base.py index d6f09088..75e8c752 100644 --- a/rio_tiler/io/base.py +++ b/rio_tiler/io/base.py @@ -282,9 +282,9 @@ def parse_expression(self, expression: str, asset_as_band: bool = False) -> Tupl assets = tuple(set(re.findall(_re, expression))) if not assets: raise InvalidExpression( - f"Could not find any valid assets in '{expression}' expression." + f"Could not find any valid assets in '{expression}' expression. Assets are: {self.assets}" if asset_as_band - else f"Could not find any valid assets in '{expression}' expression, maybe try with `asset_as_band=True`." + else f"Could not find any valid assets in '{expression}' expression, maybe try with `asset_as_band=True`. Assets are: {self.assets}" ) return assets @@ -484,7 +484,7 @@ def tile( if not assets: raise MissingAssets( - "assets must be passed either via expression or assets options." + "assets must be passed either via `expression` or `assets` options." ) asset_indexes = asset_indexes or {} @@ -512,7 +512,7 @@ def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData: if asset_as_band: if len(data.band_names) > 1: raise AssetAsBandError( - "Can't use asset_as_band for multibands asset" + "Can't use `asset_as_band` for multibands asset" ) data.band_names = [asset] else: @@ -562,7 +562,7 @@ def part( if not assets: raise MissingAssets( - "assets must be passed either via expression or assets options." + "assets must be passed either via `expression` or `assets` options." ) asset_indexes = asset_indexes or {} @@ -590,7 +590,7 @@ def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData: if asset_as_band: if len(data.band_names) > 1: raise AssetAsBandError( - "Can't use asset_as_band for multibands asset" + "Can't use `asset_as_band` for multibands asset" ) data.band_names = [asset] else: @@ -638,7 +638,7 @@ def preview( if not assets: raise MissingAssets( - "assets must be passed either via expression or assets options." + "assets must be passed either via `expression` or `assets` options." ) asset_indexes = asset_indexes or {} @@ -666,7 +666,7 @@ def _reader(asset: str, **kwargs: Any) -> ImageData: if asset_as_band: if len(data.band_names) > 1: raise AssetAsBandError( - "Can't use asset_as_band for multibands asset" + "Can't use `asset_as_band` for multibands asset" ) data.band_names = [asset] else: @@ -718,7 +718,7 @@ def point( if not assets: raise MissingAssets( - "assets must be passed either via expression or assets options." + "assets must be passed either via `expression` or `assets` options." ) asset_indexes = asset_indexes or {} @@ -740,7 +740,7 @@ def _reader(asset: str, *args, **kwargs: Any) -> PointData: if asset_as_band: if len(data.band_names) > 1: raise AssetAsBandError( - "Can't use asset_as_band for multibands asset" + "Can't use `asset_as_band` for multibands asset" ) data.band_names = [asset] else: @@ -790,7 +790,7 @@ def feature( if not assets: raise MissingAssets( - "assets must be passed either via expression or assets options." + "assets must be passed either via `expression` or `assets` options." ) asset_indexes = asset_indexes or {} @@ -818,7 +818,7 @@ def _reader(asset: str, *args: Any, **kwargs: Any) -> ImageData: if asset_as_band: if len(data.band_names) > 1: raise AssetAsBandError( - "Can't use asset_as_band for multibands asset" + "Can't use `asset_as_band` for multibands asset" ) data.band_names = [asset] else: @@ -1027,7 +1027,7 @@ def tile( if not bands: raise MissingBands( - "bands must be passed either via expression or bands options." + "bands must be passed either via `expression` or `bands` options." ) def _reader(band: str, *args: Any, **kwargs: Any) -> ImageData: @@ -1079,7 +1079,7 @@ def part( if not bands: raise MissingBands( - "bands must be passed either via expression or bands options." + "bands must be passed either via `expression` or `bands` options." ) def _reader(band: str, *args: Any, **kwargs: Any) -> ImageData: @@ -1129,7 +1129,7 @@ def preview( if not bands: raise MissingBands( - "bands must be passed either via expression or bands options." + "bands must be passed either via `expression` or `bands` options." ) def _reader(band: str, **kwargs: Any) -> ImageData: @@ -1183,7 +1183,7 @@ def point( if not bands: raise MissingBands( - "bands must be passed either via expression or bands options." + "bands must be passed either via `expression` or `bands` options." ) def _reader(band: str, *args, **kwargs: Any) -> PointData: @@ -1234,7 +1234,7 @@ def feature( if not bands: raise MissingBands( - "bands must be passed either via expression or bands options." + "bands must be passed either via `expression` or `bands` options." ) def _reader(band: str, *args: Any, **kwargs: Any) -> ImageData: diff --git a/rio_tiler/io/stac.py b/rio_tiler/io/stac.py index 96b5cdcf..fed63962 100644 --- a/rio_tiler/io/stac.py +++ b/rio_tiler/io/stac.py @@ -267,7 +267,9 @@ def __attrs_post_init__(self): ) ) if not self.assets: - raise MissingAssets("No valid asset found") + raise MissingAssets( + "No valid asset found. Asset's media types not supported" + ) @minzoom.default def _minzoom(self): @@ -288,7 +290,9 @@ def _get_asset_info(self, asset: str) -> AssetInfo: """ if asset not in self.assets: - raise InvalidAssetName(f"{asset} is not valid") + raise InvalidAssetName( + f"'{asset}' is not valid, should be one of {self.assets}" + ) asset_info = self.item.assets[asset] extras = asset_info.extra_fields