Edit on GitHub

sqlmesh.utils.errors

  1from __future__ import annotations
  2
  3import typing as t
  4from enum import auto
  5from pathlib import Path
  6
  7from sqlglot import exp
  8from sqlglot.helper import AutoName
  9
 10if t.TYPE_CHECKING:
 11    from sqlmesh.core.model import Model
 12
 13
 14class ErrorLevel(AutoName):
 15    IGNORE = auto()
 16    WARN = auto()
 17    RAISE = auto()
 18
 19
 20class SQLMeshError(Exception):
 21    pass
 22
 23
 24class ConfigError(SQLMeshError):
 25    pass
 26
 27
 28class MissingDependencyError(SQLMeshError):
 29    """Local environment is missing a required dependency for the given operation"""
 30
 31
 32class MacroEvalError(SQLMeshError):
 33    pass
 34
 35
 36class PlanError(SQLMeshError):
 37    pass
 38
 39
 40class NoChangesPlanError(PlanError):
 41    pass
 42
 43
 44class UncategorizedPlanError(PlanError):
 45    pass
 46
 47
 48class MissingContextException(Exception):
 49    pass
 50
 51
 52class SnapshotVersionError(SQLMeshError):
 53    pass
 54
 55
 56class MagicError(SQLMeshError):
 57    pass
 58
 59
 60class AuditConfigError(ConfigError):
 61    pass
 62
 63
 64class AuditError(SQLMeshError):
 65    def __init__(
 66        self,
 67        audit_name: str,
 68        count: int,
 69        query: exp.Query,
 70        model: t.Optional[Model] = None,
 71        # the dialect of the engine adapter that evaluated the audit query
 72        adapter_dialect: t.Optional[str] = None,
 73    ) -> None:
 74        self.audit_name = audit_name
 75        self.model = model
 76        self.count = count
 77        self.query = query
 78        self.adapter_dialect = adapter_dialect
 79
 80    def __str__(self) -> str:
 81        model_str = f" for model '{self.model_name}'" if self.model_name else ""
 82        return f"Audit '{self.audit_name}'{model_str} failed.\nGot {self.count} results, expected 0.\n{self.sql()}"
 83
 84    @property
 85    def model_name(self) -> t.Optional[str]:
 86        return self.model.name if self.model else None
 87
 88    def sql(self, dialect: t.Optional[str] = None, **opts: t.Any) -> str:
 89        """
 90        Returns the rendered audit query that failed.
 91
 92        Args:
 93            dialect: the dialect of the output SQL string, by default,
 94                     this will use the dialect of the engine adapter that ran the query.
 95            opts: other `sqlglot.generator.Generator` options.
 96
 97        Returns:
 98            The SQL string.
 99        """
100        return self.query.sql(dialect=dialect or self.adapter_dialect, **opts)
101
102
103class TestError(SQLMeshError):
104    pass
105
106
107class NotificationTargetError(SQLMeshError):
108    pass
109
110
111class ApiError(SQLMeshError):
112    pass
113
114
115class ApiClientError(ApiError):
116    pass
117
118
119class ApiServerError(ApiError):
120    pass
121
122
123class NotFoundError(ApiClientError):
124    pass
125
126
127class CICDBotError(SQLMeshError):
128    pass
129
130
131class ParsetimeAdapterCallError(SQLMeshError):
132    pass
133
134
135class EngineAdapterError(SQLMeshError):
136    pass
137
138
139class UnsupportedCatalogOperationError(EngineAdapterError):
140    pass
141
142
143class CircuitBreakerError(SQLMeshError):
144    def __init__(self) -> None:
145        super().__init__("Circuit breaker has been triggered.")
146
147
148def raise_config_error(
149    msg: str,
150    location: t.Optional[str | Path] = None,
151    error_type: t.Type[ConfigError] = ConfigError,
152) -> None:
153    if location:
154        raise error_type(f"{msg} at '{location}'")
155    raise error_type(msg)
class ErrorLevel(sqlglot.helper.AutoName):
15class ErrorLevel(AutoName):
16    IGNORE = auto()
17    WARN = auto()
18    RAISE = auto()

An enumeration.

IGNORE = <ErrorLevel.IGNORE: 'IGNORE'>
WARN = <ErrorLevel.WARN: 'WARN'>
RAISE = <ErrorLevel.RAISE: 'RAISE'>
Inherited Members
enum.Enum
name
value
class SQLMeshError(builtins.Exception):
21class SQLMeshError(Exception):
22    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class ConfigError(SQLMeshError):
25class ConfigError(SQLMeshError):
26    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class MissingDependencyError(SQLMeshError):
29class MissingDependencyError(SQLMeshError):
30    """Local environment is missing a required dependency for the given operation"""

Local environment is missing a required dependency for the given operation

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class MacroEvalError(SQLMeshError):
33class MacroEvalError(SQLMeshError):
34    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class PlanError(SQLMeshError):
37class PlanError(SQLMeshError):
38    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class NoChangesPlanError(PlanError):
41class NoChangesPlanError(PlanError):
42    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class UncategorizedPlanError(PlanError):
45class UncategorizedPlanError(PlanError):
46    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class MissingContextException(builtins.Exception):
49class MissingContextException(Exception):
50    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class SnapshotVersionError(SQLMeshError):
53class SnapshotVersionError(SQLMeshError):
54    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class MagicError(SQLMeshError):
57class MagicError(SQLMeshError):
58    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class AuditConfigError(ConfigError):
61class AuditConfigError(ConfigError):
62    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class AuditError(SQLMeshError):
 65class AuditError(SQLMeshError):
 66    def __init__(
 67        self,
 68        audit_name: str,
 69        count: int,
 70        query: exp.Query,
 71        model: t.Optional[Model] = None,
 72        # the dialect of the engine adapter that evaluated the audit query
 73        adapter_dialect: t.Optional[str] = None,
 74    ) -> None:
 75        self.audit_name = audit_name
 76        self.model = model
 77        self.count = count
 78        self.query = query
 79        self.adapter_dialect = adapter_dialect
 80
 81    def __str__(self) -> str:
 82        model_str = f" for model '{self.model_name}'" if self.model_name else ""
 83        return f"Audit '{self.audit_name}'{model_str} failed.\nGot {self.count} results, expected 0.\n{self.sql()}"
 84
 85    @property
 86    def model_name(self) -> t.Optional[str]:
 87        return self.model.name if self.model else None
 88
 89    def sql(self, dialect: t.Optional[str] = None, **opts: t.Any) -> str:
 90        """
 91        Returns the rendered audit query that failed.
 92
 93        Args:
 94            dialect: the dialect of the output SQL string, by default,
 95                     this will use the dialect of the engine adapter that ran the query.
 96            opts: other `sqlglot.generator.Generator` options.
 97
 98        Returns:
 99            The SQL string.
100        """
101        return self.query.sql(dialect=dialect or self.adapter_dialect, **opts)

Common base class for all non-exit exceptions.

AuditError( audit_name: str, count: int, query: sqlglot.expressions.Query, model: Union[sqlmesh.core.model.definition.SqlModel, sqlmesh.core.model.definition.SeedModel, sqlmesh.core.model.definition.PythonModel, sqlmesh.core.model.definition.ExternalModel, NoneType] = None, adapter_dialect: Union[str, NoneType] = None)
66    def __init__(
67        self,
68        audit_name: str,
69        count: int,
70        query: exp.Query,
71        model: t.Optional[Model] = None,
72        # the dialect of the engine adapter that evaluated the audit query
73        adapter_dialect: t.Optional[str] = None,
74    ) -> None:
75        self.audit_name = audit_name
76        self.model = model
77        self.count = count
78        self.query = query
79        self.adapter_dialect = adapter_dialect
def sql(self, dialect: Union[str, NoneType] = None, **opts: Any) -> str:
 89    def sql(self, dialect: t.Optional[str] = None, **opts: t.Any) -> str:
 90        """
 91        Returns the rendered audit query that failed.
 92
 93        Args:
 94            dialect: the dialect of the output SQL string, by default,
 95                     this will use the dialect of the engine adapter that ran the query.
 96            opts: other `sqlglot.generator.Generator` options.
 97
 98        Returns:
 99            The SQL string.
100        """
101        return self.query.sql(dialect=dialect or self.adapter_dialect, **opts)

Returns the rendered audit query that failed.

Arguments:
  • dialect: the dialect of the output SQL string, by default, this will use the dialect of the engine adapter that ran the query.
  • opts: other sqlglot.generator.Generator options.
Returns:

The SQL string.

Inherited Members
builtins.BaseException
with_traceback
class TestError(SQLMeshError):
104class TestError(SQLMeshError):
105    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class NotificationTargetError(SQLMeshError):
108class NotificationTargetError(SQLMeshError):
109    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class ApiError(SQLMeshError):
112class ApiError(SQLMeshError):
113    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class ApiClientError(ApiError):
116class ApiClientError(ApiError):
117    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class ApiServerError(ApiError):
120class ApiServerError(ApiError):
121    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class NotFoundError(ApiClientError):
124class NotFoundError(ApiClientError):
125    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class CICDBotError(SQLMeshError):
128class CICDBotError(SQLMeshError):
129    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class ParsetimeAdapterCallError(SQLMeshError):
132class ParsetimeAdapterCallError(SQLMeshError):
133    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class EngineAdapterError(SQLMeshError):
136class EngineAdapterError(SQLMeshError):
137    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class UnsupportedCatalogOperationError(EngineAdapterError):
140class UnsupportedCatalogOperationError(EngineAdapterError):
141    pass

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
class CircuitBreakerError(SQLMeshError):
144class CircuitBreakerError(SQLMeshError):
145    def __init__(self) -> None:
146        super().__init__("Circuit breaker has been triggered.")

Common base class for all non-exit exceptions.

Inherited Members
builtins.BaseException
with_traceback
def raise_config_error( msg: str, location: 't.Optional[str | Path]' = None, error_type: Type[sqlmesh.utils.errors.ConfigError] = <class 'sqlmesh.utils.errors.ConfigError'>) -> None:
149def raise_config_error(
150    msg: str,
151    location: t.Optional[str | Path] = None,
152    error_type: t.Type[ConfigError] = ConfigError,
153) -> None:
154    if location:
155        raise error_type(f"{msg} at '{location}'")
156    raise error_type(msg)