|
18 | 18 |
|
19 | 19 | import json |
20 | 20 |
|
| 21 | +import pytest |
21 | 22 | from pytest_mock import MockerFixture |
22 | 23 |
|
| 24 | +from superset.db_engine_specs.databricks import DatabricksNativeEngineSpec |
| 25 | +from superset.errors import ErrorLevel, SupersetError, SupersetErrorType |
23 | 26 | from superset.utils.core import GenericDataType |
24 | 27 |
|
25 | 28 |
|
@@ -197,3 +200,56 @@ def test_get_extra_params(mocker: MockerFixture) -> None: |
197 | 200 | } |
198 | 201 | } |
199 | 202 | } |
| 203 | + |
| 204 | + |
| 205 | +def test_extract_errors() -> None: |
| 206 | + """ |
| 207 | + Test that custom error messages are extracted correctly. |
| 208 | + """ |
| 209 | + |
| 210 | + msg = ": mismatched input 'fromm'. Expecting: " |
| 211 | + result = DatabricksNativeEngineSpec.extract_errors(Exception(msg)) |
| 212 | + |
| 213 | + assert result == [ |
| 214 | + SupersetError( |
| 215 | + message=": mismatched input 'fromm'. Expecting: ", |
| 216 | + error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR, |
| 217 | + level=ErrorLevel.ERROR, |
| 218 | + extra={ |
| 219 | + "engine_name": "Databricks", |
| 220 | + "issue_codes": [ |
| 221 | + { |
| 222 | + "code": 1002, |
| 223 | + "message": "Issue 1002 - The database returned an unexpected error.", |
| 224 | + } |
| 225 | + ], |
| 226 | + }, |
| 227 | + ) |
| 228 | + ] |
| 229 | + |
| 230 | + |
| 231 | +def test_extract_errors_with_context() -> None: |
| 232 | + """ |
| 233 | + Test that custom error messages are extracted correctly with context. |
| 234 | + """ |
| 235 | + |
| 236 | + msg = ": mismatched input 'fromm'. Expecting: " |
| 237 | + context = {"hostname": "foo"} |
| 238 | + result = DatabricksNativeEngineSpec.extract_errors(Exception(msg), context) |
| 239 | + |
| 240 | + assert result == [ |
| 241 | + SupersetError( |
| 242 | + message=": mismatched input 'fromm'. Expecting: ", |
| 243 | + error_type=SupersetErrorType.GENERIC_DB_ENGINE_ERROR, |
| 244 | + level=ErrorLevel.ERROR, |
| 245 | + extra={ |
| 246 | + "engine_name": "Databricks", |
| 247 | + "issue_codes": [ |
| 248 | + { |
| 249 | + "code": 1002, |
| 250 | + "message": "Issue 1002 - The database returned an unexpected error.", |
| 251 | + } |
| 252 | + ], |
| 253 | + }, |
| 254 | + ) |
| 255 | + ] |
0 commit comments