Skip to content

Commit

Permalink
Update QueryFailed error to include failure info. (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Oct 10, 2023
1 parent a769b48 commit d97bc15
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dune_client/api/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,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

0 comments on commit d97bc15

Please sign in to comment.