Skip to content

Commit

Permalink
Improved message for GetChunkError (#2844)
Browse files Browse the repository at this point in the history
Improved message for GetChunkError
  • Loading branch information
nvoxland-al committed May 7, 2024
1 parent 5ec72ac commit b1a13a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions deeplake/core/chunk_engine.py
Expand Up @@ -603,7 +603,7 @@ def get_chunk_from_chunk_id(
chunk = self.copy_chunk_to_new_commit(chunk, chunk_name)
return chunk
except Exception as e:
raise GetChunkError(chunk_key) from e
raise GetChunkError(chunk_key, cause=e) from e

def get_video_chunk(self, chunk_id, copy: bool = False):
"""Returns video chunks. Chunk will contain presigned url to the video instead of data if the chunk is large."""
Expand Down Expand Up @@ -2298,7 +2298,7 @@ def _get_samples(
else:
sample = self.get_single_sample(idx, index, pad_tensor=pad_tensor)
except GetChunkError as e:
raise GetChunkError(e.chunk_key, idx, self.name) from e
raise GetChunkError(e.chunk_key, idx, self.name, e) from e
except ReadSampleFromChunkError as e:
raise ReadSampleFromChunkError(e.chunk_key, idx, self.name) from e
check_sample_shape(sample.shape, last_shape, self.key, index, aslist)
Expand Down Expand Up @@ -2396,7 +2396,7 @@ def _numpy(
)
except GetChunkError as e:
raise GetChunkError(
e.chunk_key, global_sample_index, self.name
e.chunk_key, global_sample_index, self.name, e
) from e
except ReadSampleFromChunkError as e:
raise ReadSampleFromChunkError(
Expand Down
14 changes: 14 additions & 0 deletions deeplake/util/exceptions.py
Expand Up @@ -993,8 +993,14 @@ def __init__(
chunk_key: Optional[str],
global_index: Optional[int] = None,
tensor_name: Optional[str] = None,
cause: Optional[Exception] = None,
):
self.root_cause = cause
self.chunk_key = chunk_key

if isinstance(cause, GetChunkError):
self.root_cause = cause.root_cause

message = "Unable to get chunk"
if chunk_key is not None:
message += f" '{chunk_key}'"
Expand All @@ -1003,6 +1009,14 @@ def __init__(
if tensor_name is not None:
message += f" in tensor {tensor_name}"
message += "."

if cause is not None:
cause_message = str(cause)
if isinstance(cause, KeyError):
cause_message = f"The file {cause} does not exist."

message += f" Root Cause: {cause_message}"

super().__init__(message)


Expand Down

0 comments on commit b1a13a9

Please sign in to comment.