Skip to content

Commit

Permalink
Add more specific error message for trycatch landlab ImportError
Browse files Browse the repository at this point in the history
  • Loading branch information
araistrick authored and pvl-bot committed Sep 27, 2024
1 parent d55e297 commit b3ab846
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions infinigen/terrain/assets/upsidedown_mountains.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
FlowDirectorSteepest,
TransportLengthHillslopeDiffuser,
)
except ImportError:
except ImportError as e:
landlab = None
_landlab_import_error = e

from infinigen.core.util.organization import AssetFile
from infinigen.core.util.random import random_general as rg
Expand Down Expand Up @@ -53,9 +54,10 @@ def upsidedown_mountains_asset(

if landlab is None:
raise ImportError(
"landlab must be installed to use terrain mountain simulation "
"Please install optional terrain dependencies via `pip install .[terrain]`"
)
"landlab import failed for terrain mountain simulation "
f" original error: {_landlab_import_error}\n"
"You may need to install terrain dependencies via `pip install .[terrain]`"
) from _landlab_import_error

Path(folder).mkdir(parents=True, exist_ok=True)
N = resolution
Expand Down
10 changes: 6 additions & 4 deletions infinigen/terrain/land_process/snowfall.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
FlowDirectorSteepest,
TransportLengthHillslopeDiffuser,
)
except ImportError:
except ImportError as e:
_landlab_import_error = e
landlab = None

from infinigen.core.util.organization import AssetFile, Process
Expand Down Expand Up @@ -57,9 +58,10 @@ def run_snowfall(
):
if landlab is None:
raise ImportError(
"landlab must be installed to use terrain snowfall "
"Please install optional terrain dependencies via `pip install .[terrain]`"
)
"landlab import failed for terrain snowfall simulation\n"
f" original error: {_landlab_import_error}\n"
"You may need to install terrain dependencies via `pip install .[terrain]`"
) from _landlab_import_error

heightmap_path = f"{folder}/{Process.Erosion}.{AssetFile.Heightmap}.exr"
tile_size = float(np.loadtxt(f"{folder}/{AssetFile.TileSize}.txt"))
Expand Down

0 comments on commit b3ab846

Please sign in to comment.