Skip to content

Commit

Permalink
Improve error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Nov 13, 2024
1 parent b8b76a3 commit fa82d23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def assert_snapshot_text_equal(
expectation_description: Optional[str] = None,
) -> None:
"""Similar to assert_plan_snapshot_text_equal(), but with more controls on how the snapshot paths are generated."""
logger.debug(LazyFormat(lambda: "Generated snapshot text:\n" + indent(snapshot_text)))
file_path = (
str(
snapshot_path_prefix(
Expand Down
14 changes: 12 additions & 2 deletions metricflow/dataset/sql_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dbt_semantic_interfaces.references import SemanticModelReference
from metricflow_semantics.assert_one_arg import assert_exactly_one_arg_set
from metricflow_semantics.instances import EntityInstance, InstanceSet
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat
from metricflow_semantics.specs.column_assoc import ColumnAssociation
from metricflow_semantics.specs.dimension_spec import DimensionSpec
from metricflow_semantics.specs.entity_spec import EntitySpec
Expand Down Expand Up @@ -42,7 +43,9 @@ def __init__(
def sql_node(self) -> SqlQueryPlanNode: # noqa: D102
node_to_return = self._sql_select_node or self._sql_node
if node_to_return is None:
raise RuntimeError("This node was not created with a SQL node.")
raise RuntimeError(
"This node was not created with a SQL node. This should have been prevented by the initializer."
)
return node_to_return

@property
Expand All @@ -52,7 +55,14 @@ def checked_sql_select_node(self) -> SqlSelectStatementNode:
Otherwise, an exception is thrown.
"""
if self._sql_select_node is None:
raise RuntimeError(f"{self} was created with a SQL node that is not a {SqlSelectStatementNode}")
raise RuntimeError(
str(
LazyFormat(
f"{self.__class__.__name__} was created with a SQL node that is not a {SqlSelectStatementNode.__name__}",
sql_node=self.sql_node.structure_text(),
)
)
)
return self._sql_select_node

def column_associations_for_entity(
Expand Down

0 comments on commit fa82d23

Please sign in to comment.