Skip to content

Commit

Permalink
Cleanup: Better error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Jan 27, 2025
1 parent d60d490 commit dbeded9
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions metricflow/plan_conversion/instance_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
MetricInstance,
TimeDimensionInstance,
)
from metricflow_semantics.mf_logging.lazy_formattable import LazyFormat
from metricflow_semantics.model.semantics.metric_lookup import MetricLookup
from metricflow_semantics.model.semantics.semantic_model_lookup import SemanticModelLookup
from metricflow_semantics.specs.column_assoc import ColumnAssociationResolver
Expand Down Expand Up @@ -449,26 +450,37 @@ def _should_pass(self, element_spec: InstanceSpec) -> bool:

def transform(self, instance_set: InstanceSet) -> InstanceSet: # noqa: D102
# Sanity check to make sure the specs are in the instance set

available_specs = instance_set.spec_set.all_specs
if self._include_specs:
include_specs_not_found = []
for include_spec in self._include_specs.all_specs:
if include_spec not in instance_set.spec_set.all_specs:
if include_spec not in available_specs:
include_specs_not_found.append(include_spec)
if include_specs_not_found:
raise RuntimeError(
f"Include specs {include_specs_not_found} are not in the spec set {instance_set.spec_set} - "
f"check if this node was constructed correctly."
str(
LazyFormat(
"Include specs are not in the spec set - check if this node was constructed correctly.",
include_specs_not_found=include_specs_not_found,
available_specs=available_specs,
)
)
)
elif self._exclude_specs:
exclude_specs_not_found = []

for exclude_spec in self._exclude_specs.all_specs:
if exclude_spec not in instance_set.spec_set.all_specs:
if exclude_spec not in available_specs:
exclude_specs_not_found.append(exclude_spec)
if exclude_specs_not_found:
raise RuntimeError(
f"Exclude specs {exclude_specs_not_found} are not in the spec set {instance_set.spec_set} - "
f"check if this node was constructed correctly."
str(
LazyFormat(
"Exclude specs are not in the spec set - check if this node was constructed correctly.",
exclude_specs_not_found=exclude_specs_not_found,
available_specs=available_specs,
)
)
)
else:
assert False, "Include specs or exclude specs should have been specified."
Expand Down

0 comments on commit dbeded9

Please sign in to comment.