INNER CODE UNIT · Python
_bail_on_error
marc-shade/world-intel-mcp · src/world_intel_mcp/cli.py:96
def _bail_on_error(ctx: click.Context, data: dict) -> bool:
"""True when the command should stop rendering.
In --json-output mode the raw dict (error included) is printed
unchanged. In table mode an upstream {"error": ...} is printed in red
so an outage is never shape-identical to a quiet world ("0
earthquakes", "No market data available"). Degraded-but-partial
payloads carry no top-level "error" key and fall through to normal
rendering.
"""
if ctx.obj.get("json"):
_print_json(data)
return True
if "error" in data:
console.print(f"[red]Error:[/red] {escape(str(data['error']))}")
return True
return False