Error Tracebacks¶
How TANGO adds context to an error as it travels up the call stack, so that a failure names the component, the timestep and iteration, and the original message. Status: available for CoolProp errors.
Goal¶
An error raised deep inside a property call should tell the reader three things:
- Where: which component, and its index in the circuit.
- When: which timestep and simulated time, and which convergence iteration.
- What: the original error message, unchanged.
Each layer of the call stack catches the error, adds the context it knows
and re-raises it with raise ... from exc, so the original traceback stays
attached.
CoolProp errors¶
CoolProp property updates are wrapped in src/tango_core/core/fluid_state.py.
A failed update, for example a negative pressure, raises CoolPropError
with the inputs that caused it:
def update_PT(self, P: float, T: float) -> None:
"""Update this state in place from pressure (Pa) and temperature (K)."""
try:
self._state.update(CoolProp.PT_INPUTS, P, T)
except ValueError as exc:
raise CoolPropError(
f"updatePT(P={P:.6g} Pa, T={T:.6g} K) failed for {self.fluid_name}: {exc}",
) from exc
SystemDirect._solve_interval (src/tango_core/orchestrators/system_direct.py)
adds where: the component and the step it was solving.
try:
outlet = component.solve(self._inlet_for(component, step), step)
except CoolPropError as exc:
raise CoolPropError(
f"Component: {component.__class__.__name__} (component_idx "
f"{component.component_idx}), step from {step.t_start:.6g} s to "
f"{step.t_end:.6g} s\n{exc}",
) from exc
SystemBCIteration._converge_injection_enthalpy
(src/tango_core/orchestrators/system_bc_iteration.py) adds the iteration
of the injection-enthalpy loop. A "Tmelt" error is the one exception: the
guess drove water below its freezing point, so the loop resets the guess to
275 K and retries instead of failing.
try:
self._solve_interval(interval)
except CoolPropError as exc:
if "Tmelt" not in str(exc):
raise CoolPropError(f"""
Converge Injection Enthalpy Iteration: {inner_iter}
{exc}
""") from exc
... # reset the guess to 275 K and retry
SystemBCIteration.run_interval adds when, the sync interval:
try:
self._converge_injection_enthalpy(circuit_entry, surface, snapshot, interval)
except CoolPropError as exc:
raise CoolPropError(f"""
Sync interval: {i}
Time: {interval.t_start:.6g} s to {interval.t_end:.6g} s
{exc}
""") from exc
SystemDirect.run_interval adds the sync interval, because it has no inner
loop.
The wrapped CoolProp inputs are:
CoolProp.HmassP_INPUTS(FluidState.update_HP)CoolProp.PT_INPUTS(FluidState.update_PT)
A failed TESPy network solve in the surface plant raises
TESPyCoolPropError (src/tango_core/components/surface/graph.py). It
subclasses CoolPropError, so the same orchestrator layers add where and
when. Every TangoError that reaches tango_core run ends the run with exit
code 2.