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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update QueryFailed error to include failure info. #96

Merged
merged 3 commits into from
Oct 10, 2023
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
2 changes: 1 addition & 1 deletion dune_client/api/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ def _refresh(
status = self.get_execution_status(job_id)
if status.state == ExecutionState.FAILED:
self.logger.error(status)
raise QueryFailed(f"{status}. Perhaps your query took too long to run!")
raise QueryFailed(f"Error data: {status.error}")

return job_id
2 changes: 1 addition & 1 deletion dune_client/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ async def _refresh(
status = await self.get_status(job_id)
if status.state == ExecutionState.FAILED:
self.logger.error(status)
raise QueryFailed(f"{status}. Perhaps your query took too long to run!")
raise QueryFailed(f"Error data: {status.error}")

return job_id

Expand Down
30 changes: 30 additions & 0 deletions dune_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,33 @@ def from_dict(cls, data: dict[str, Any]) -> TimeData:
)


@dataclass
class ExecutionError:
"""
Representation of Execution Error Response:

Example:
{
"type":"FAILED_TYPE_EXECUTION_FAILED",
"message":"line 24:13: Binary literal can only contain hexadecimal digits",
"metadata":{"line":24,"column":13}
}
"""

type: str
message: str
metadata: str

@classmethod
def from_dict(cls, data: dict[str, str]) -> ExecutionError:
"""Constructs an instance from a dict"""
return cls(
type=data.get("type", "unknown"),
message=data.get("message", "unknown"),
metadata=data.get("metadata", "unknown"),
)


@dataclass
class ExecutionStatusResponse:
"""
Expand All @@ -119,18 +146,21 @@ class ExecutionStatusResponse:
queue_position: Optional[int]
# this will be present when the query execution completes
result_metadata: Optional[ResultMetadata]
error: Optional[ExecutionError]

@classmethod
def from_dict(cls, data: dict[str, Any]) -> ExecutionStatusResponse:
"""Constructor from dictionary. See unit test for sample input."""
dct: Optional[MetaData] = data.get("result_metadata")
error: Optional[dict[str, str]] = data.get("error")
return cls(
execution_id=data["execution_id"],
query_id=int(data["query_id"]),
queue_position=data.get("queue_position"),
state=ExecutionState(data["state"]),
result_metadata=ResultMetadata.from_dict(dct) if dct else None,
times=TimeData.from_dict(data), # Sending the entire data dict
error=ExecutionError.from_dict(error) if error else None,
)

def __str__(self) -> str:
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_parse_status_response(self):
times=TimeData.from_dict(self.status_response_data),
result_metadata=None,
queue_position=None,
error=None,
)
self.assertEqual(
expected, ExecutionStatusResponse.from_dict(self.status_response_data)
Expand Down Expand Up @@ -160,6 +161,7 @@ def test_parse_status_response_completed(self):
times=TimeData.from_dict(self.status_response_data),
result_metadata=ResultMetadata.from_dict(self.result_metadata_data),
queue_position=None,
error=None,
),
ExecutionStatusResponse.from_dict(self.status_response_data_completed),
)
Expand Down