Skip to content

Commit

Permalink
add asset list in error message (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago authored Oct 5, 2023
1 parent 8997564 commit dd13e53
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 17 additions & 17 deletions rio_tiler/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {}
Expand All @@ -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:
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions rio_tiler/io/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down

0 comments on commit dd13e53

Please sign in to comment.