Division by zero crashes

Done

Devanshi-cmd/devswarm-demo#1 · 2026-11-09 15:24:46 UTC · took 30.9s

  1. Plan (done)
  2. Code (done)
  3. Test (done)
  4. Review (done)
  5. Finish (done)
Cost
$0.0044
Tests
Passed
Iterations
1
Re-plans
0
LLM calls
11
Prompt read from cache
57%

Usage by agent

Cost per agent
planner: $0.0009 planner planner, Cost: $0.0009 $0.0009 coder: $0.0011 coder coder, Cost: $0.0011 $0.0011 tester: $0.0015 tester tester, Cost: $0.0015 $0.0015 reviewer: $0.0009 reviewer reviewer, Cost: $0.0009 $0.0009
Tokens per agent
  • Cache read
  • Cache write
  • Input
  • Output
planner: 8,182 planner planner, Cache read: 4,341 planner, Cache write: 2,925 planner, Output: 908 8,182 coder: 12.7K coder coder, Cache read: 7,078 coder, Cache write: 4,729 coder, Output: 919 12.7K tester: 15.7K tester tester, Cache read: 8,483 tester, Cache write: 5,791 tester, Output: 1,459 15.7K reviewer: 8,831 reviewer reviewer, Cache read: 3,663 reviewer, Cache write: 4,591 reviewer, Output: 571 8,831
View as table
AgentCostCache readCache writeInputOutput
planner$0.00094,3412,9258908
coder$0.00117,0784,7298919
tester$0.00158,4835,79181,459
reviewer$0.00093,6634,5916571

Timeline

  1. planner iteration 1 Finished 3 calls · 8,182 tokens · $0.0009 · 7.7s

    Loading…

  2. coder iteration 1 Finished 3 calls · 12.7K tokens · $0.0011 · 6.0s

    Loading…

  3. tester iteration 1 Finished 3 calls · 15.7K tokens · $0.0015 · 9.7s

    Loading…

  4. verify iteration 1 Passed 0.6s
    ..............                                                           [100%]
    14 passed in 0.07s
    
  5. reviewer iteration 1 Finished 2 calls · 8,831 tokens · $0.0009 · 4.9s

    Loading…

Final diff

diff --git a/calc.py b/calc.py
index f16c6ca..b7d522d 100644
--- a/calc.py
+++ b/calc.py
@@ -15,6 +15,8 @@ def calculate(left: float, operator: str, right: float) -> float:
     if operator == "*":
         return left * right
     if operator == "/":
+        if right == 0:
+            raise CalculatorError("division by zero")
         return left / right
     raise CalculatorError(f"unknown operator: {operator}")
 
diff --git a/test_calc.py b/test_calc.py
index 856b0c9..4330e7c 100644
--- a/test_calc.py
+++ b/test_calc.py
@@ -23,3 +23,46 @@ def test_main_prints_result(capsys):
 def test_main_reports_unknown_operator(capsys):
     assert main(["1", "%", "2"]) == 1
     assert "unknown operator" in capsys.readouterr().err
+
+
+def test_division_by_zero_raises_calculator_error():
+    with pytest.raises(CalculatorError, match="division by zero"):
+        calculate(1, "/", 0)
+
+
+def test_main_reports_division_by_zero(capsys):
+    assert main(["1", "/", "0"]) == 1
+    assert "division by zero" in capsys.readouterr().err
+
+
+@pytest.mark.parametrize("zero", [0.0, -0.0])
+def test_float_zero_divisor_raises_calculator_error(zero):
+    with pytest.raises(CalculatorError, match="division by zero"):
+        calculate(1.0, "/", zero)
+
+
+def test_nan_divisor_keeps_float_semantics():
+    import math
+
+    assert math.isnan(calculate(1.0, "/", float("nan")))
+
+
+def test_inf_divisor_keeps_float_semantics():
+    assert calculate(1.0, "/", float("inf")) == 0.0
+
+
+def test_cli_division_by_zero_exits_1_without_traceback():
+    import subprocess
+    import sys
+    from pathlib import Path
+
+    script = Path(__file__).parent / "calc.py"
+    proc = subprocess.run(
+        [sys.executable, str(script), "1", "/", "0"],
+        capture_output=True,
+        text=True,
+    )
+    assert proc.returncode == 1
+    assert "division by zero" in proc.stderr
+    assert "Traceback" not in proc.stderr
+    assert proc.stdout == ""