|
5 | 5 | from collections.abc import Iterator |
6 | 6 | from datetime import timedelta |
7 | 7 |
|
| 8 | +from databricks.sdk import errors |
| 9 | +from databricks.sdk.errors import NotFound |
8 | 10 | from databricks.sdk.service.sql import ( |
9 | 11 | ColumnInfoTypeName, |
10 | 12 | Disposition, |
11 | 13 | ExecuteStatementResponse, |
12 | 14 | Format, |
13 | 15 | ResultData, |
| 16 | + ServiceErrorCode, |
14 | 17 | StatementExecutionAPI, |
15 | 18 | StatementState, |
16 | 19 | StatementStatus, |
@@ -91,10 +94,28 @@ def __init__(self, api_client): |
91 | 94 | def _raise_if_needed(status: StatementStatus): |
92 | 95 | if status.state not in [StatementState.FAILED, StatementState.CANCELED, StatementState.CLOSED]: |
93 | 96 | return |
94 | | - msg = status.state.value |
95 | | - if status.error is not None: |
96 | | - msg = f"{msg}: {status.error.error_code.value} {status.error.message}" |
97 | | - raise RuntimeError(msg) |
| 97 | + if "SCHEMA_NOT_FOUND" in status.error.message: |
| 98 | + raise NotFound(status.error.message) |
| 99 | + if "TABLE_NOT_FOUND" in status.error.message: |
| 100 | + raise NotFound(status.error.message) |
| 101 | + mapping = { |
| 102 | + ServiceErrorCode.ABORTED: errors.Aborted, |
| 103 | + ServiceErrorCode.ALREADY_EXISTS: errors.AlreadyExists, |
| 104 | + ServiceErrorCode.BAD_REQUEST: errors.BadRequest, |
| 105 | + ServiceErrorCode.CANCELLED: errors.Cancelled, |
| 106 | + ServiceErrorCode.DEADLINE_EXCEEDED: errors.DeadlineExceeded, |
| 107 | + ServiceErrorCode.INTERNAL_ERROR: errors.InternalError, |
| 108 | + ServiceErrorCode.IO_ERROR: errors.InternalError, |
| 109 | + ServiceErrorCode.NOT_FOUND: errors.NotFound, |
| 110 | + ServiceErrorCode.RESOURCE_EXHAUSTED: errors.ResourceExhausted, |
| 111 | + ServiceErrorCode.SERVICE_UNDER_MAINTENANCE: errors.TemporarilyUnavailable, |
| 112 | + ServiceErrorCode.TEMPORARILY_UNAVAILABLE: errors.TemporarilyUnavailable, |
| 113 | + ServiceErrorCode.UNAUTHENTICATED: errors.Unauthenticated, |
| 114 | + ServiceErrorCode.UNKNOWN: errors.Unknown, |
| 115 | + ServiceErrorCode.WORKSPACE_TEMPORARILY_UNAVAILABLE: errors.TemporarilyUnavailable, |
| 116 | + } |
| 117 | + error_class = mapping.get(status.error.error_code, errors.Unknown) |
| 118 | + raise error_class(status.error.message) |
98 | 119 |
|
99 | 120 | def execute( |
100 | 121 | self, |
|
0 commit comments