From fa82d231c4cfcb61b7e907b4a134315578ca1e7c Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Fri, 8 Nov 2024 12:53:04 -0800 Subject: [PATCH] Improve error messages. --- .../test_helpers/snapshot_helpers.py | 1 + metricflow/dataset/sql_dataset.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/test_helpers/snapshot_helpers.py b/metricflow-semantics/metricflow_semantics/test_helpers/snapshot_helpers.py index 5d75f9e1d0..4d8309f282 100644 --- a/metricflow-semantics/metricflow_semantics/test_helpers/snapshot_helpers.py +++ b/metricflow-semantics/metricflow_semantics/test_helpers/snapshot_helpers.py @@ -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( diff --git a/metricflow/dataset/sql_dataset.py b/metricflow/dataset/sql_dataset.py index b38da60910..363dbac333 100644 --- a/metricflow/dataset/sql_dataset.py +++ b/metricflow/dataset/sql_dataset.py @@ -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 @@ -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 @@ -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(