Skip to content

Commit 132a739

Browse files
committed
improve _open_dataset_with_fallback to preserve original error behavior
1 parent 774c591 commit 132a739

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

uxarray/core/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ def _open_dataset_with_fallback(filename_or_obj, chunks=None, **kwargs):
3131
try:
3232
# Try opening with xarray's default read engine
3333
return xr.open_dataset(filename_or_obj, chunks=chunks, **kwargs)
34-
except Exception:
35-
# If it fails, use the "netcdf4" engine as backup
34+
except Exception as first_error:
35+
# If it fails, try with the "netcdf4" engine as backup
3636
# Extract engine from kwargs to prevent duplicate parameter error
3737
engine = kwargs.pop("engine", "netcdf4")
38-
return xr.open_dataset(filename_or_obj, engine=engine, chunks=chunks, **kwargs)
38+
try:
39+
return xr.open_dataset(
40+
filename_or_obj, engine=engine, chunks=chunks, **kwargs
41+
)
42+
except Exception:
43+
# If both attempts fail, raise the original error to preserve the original behavior
44+
raise first_error
3945

4046

4147
def _map_dims_to_ugrid(

0 commit comments

Comments
 (0)