diff options
Diffstat (limited to 'sqlglot/errors.py')
-rw-r--r-- | sqlglot/errors.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/sqlglot/errors.py b/sqlglot/errors.py index 23a08bd..b5ef5ad 100644 --- a/sqlglot/errors.py +++ b/sqlglot/errors.py @@ -22,7 +22,40 @@ class UnsupportedError(SqlglotError): class ParseError(SqlglotError): - pass + def __init__( + self, + message: str, + errors: t.Optional[t.List[t.Dict[str, t.Any]]] = None, + ): + super().__init__(message) + self.errors = errors or [] + + @classmethod + def new( + cls, + message: str, + description: t.Optional[str] = None, + line: t.Optional[int] = None, + col: t.Optional[int] = None, + start_context: t.Optional[str] = None, + highlight: t.Optional[str] = None, + end_context: t.Optional[str] = None, + into_expression: t.Optional[str] = None, + ) -> ParseError: + return cls( + message, + [ + { + "description": description, + "line": line, + "col": col, + "start_context": start_context, + "highlight": highlight, + "end_context": end_context, + "into_expression": into_expression, + } + ], + ) class TokenError(SqlglotError): @@ -41,9 +74,13 @@ class ExecuteError(SqlglotError): pass -def concat_errors(errors: t.Sequence[t.Any], maximum: int) -> str: +def concat_messages(errors: t.Sequence[t.Any], maximum: int) -> str: msg = [str(e) for e in errors[:maximum]] remaining = len(errors) - maximum if remaining > 0: msg.append(f"... and {remaining} more") return "\n\n".join(msg) + + +def merge_errors(errors: t.Sequence[ParseError]) -> t.List[t.Dict[str, t.Any]]: + return [e_dict for error in errors for e_dict in error.errors] |