Repository navigation
Expand file tree
/
Copy pathesql_errors.py
More file actions
83 lines (57 loc) · 2.24 KB
/
Copy pathesql_errors.py
File metadata and controls
83 lines (57 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
# or more contributor license agreements. Licensed under the Elastic License
# 2.0; you may not use this file except in compliance with the Elastic License
# 2.0.
"""ESQL exceptions."""
from .misc import ClientError
__all__ = (
"EsqlKibanaBaseError",
"EsqlSchemaError",
"EsqlSemanticError",
"EsqlSyntaxError",
"EsqlTypeMismatchError",
"EsqlUnknownIndexError",
"EsqlUnsupportedTypeError",
"public_esql_error",
)
class EsqlKibanaBaseError(ClientError):
"""Base class for offline ES|QL validation errors."""
def __init__(self, message: str) -> None:
super().__init__(message, original_error=self)
class EsqlSchemaError(EsqlKibanaBaseError):
"""Error in an ES|QL schema check."""
class EsqlUnsupportedTypeError(EsqlKibanaBaseError):
"""Error in ES|QL type validation using an unsupported type."""
class EsqlSyntaxError(EsqlKibanaBaseError):
"""Error with ES|QL syntax."""
class EsqlTypeMismatchError(ClientError):
"""Error when an ES|QL expression compares incompatible types."""
def __init__(self, message: str) -> None:
super().__init__(message, original_error=self)
class EsqlSemanticError(ClientError):
"""Error with ES|QL semantics."""
def __init__(self, message: str) -> None:
super().__init__(message, original_error=self)
class EsqlUnknownIndexError(ClientError):
"""Error when an ES|QL FROM or LOOKUP JOIN pattern is unknown."""
def __init__(self, message: str) -> None:
super().__init__(message, original_error=self)
def public_esql_error(exc: BaseException) -> Exception:
"""Map a parser exception onto a detection-rules ES|QL error."""
import esql
if isinstance(exc, esql.EsqlSyntaxError):
return EsqlSyntaxError(str(exc))
if isinstance(exc, esql.EsqlSchemaError):
return EsqlSchemaError(str(exc))
if isinstance(exc, esql.EsqlTypeMismatchError):
return EsqlTypeMismatchError(str(exc))
return EsqlSemanticError(str(exc))
ESQL_EXCEPTION_TYPES = (
EsqlSchemaError,
EsqlSyntaxError,
EsqlUnsupportedTypeError,
EsqlTypeMismatchError,
EsqlKibanaBaseError,
EsqlSemanticError,
EsqlUnknownIndexError,
)