From 20dee2b48805ff5badd1c00604535389503cc010 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 10 Mar 2026 05:52:09 -0400 Subject: [PATCH] Log exceptions instead of silently swallowing them in calculate The axes code path silently discarded all exceptions (`pass`), causing variables like NJ gross income to return null with no error trace. Now logs the full traceback via logging.exception(). Fixes #3322 Co-Authored-By: Claude Opus 4.6 --- changelog.d/fix-silent-exception-swallowing.fixed.md | 1 + policyengine_api/country.py | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 changelog.d/fix-silent-exception-swallowing.fixed.md diff --git a/changelog.d/fix-silent-exception-swallowing.fixed.md b/changelog.d/fix-silent-exception-swallowing.fixed.md new file mode 100644 index 00000000..4b10062e --- /dev/null +++ b/changelog.d/fix-silent-exception-swallowing.fixed.md @@ -0,0 +1 @@ +Log exceptions instead of silently swallowing them during household calculations. diff --git a/policyengine_api/country.py b/policyengine_api/country.py index befa4985..0cc7f380 100644 --- a/policyengine_api/country.py +++ b/policyengine_api/country.py @@ -1,4 +1,5 @@ import importlib +import logging from flask import Response import json from policyengine_core.taxbenefitsystems import TaxBenefitSystem @@ -445,11 +446,9 @@ def calculate( entity_result ) except Exception as e: - if "axes" in household: - pass - else: + logging.exception(f"Error computing {variable_name} for {entity_id}") + if "axes" not in household: household[entity_plural][entity_id][variable_name][period] = None - print(f"Error computing {variable_name} for {entity_id}: {e}") tracer_output = simulation.tracer.computation_log log_lines = tracer_output.lines(aggregate=False, max_depth=10)