Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved message for GetChunkError #2844

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deeplake/core/chunk_engine.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading