Skip to content

🤖 Fix: ZeroDivisionError - division by zero in calculate endpoint - default b#1

Open
zoetaka38 wants to merge 1 commit into
mainfrom
autofix/zerodivisionerror-20260417-080314
Open

🤖 Fix: ZeroDivisionError - division by zero in calculate endpoint - default b#1
zoetaka38 wants to merge 1 commit into
mainfrom
autofix/zerodivisionerror-20260417-080314

Conversation

@zoetaka38

Copy link
Copy Markdown
Contributor

🤖 AI Generated Fix

Error Details

  • Type: ZeroDivisionError
  • Message: division by zero in calculate endpoint - default b=0

Claude Code Output

全テスト通過しました。

---

## 修正内容の説明

### 根本原因
`app.py:18` でクエリパラメータ `b` のデフォルト値が `0` に設定されていたため、`/calculate?a=10` のように `b` を省略するとゼロ除算が発生していました。

### 修正内容(`app.py:17-20`)

| 変更点 | 修正前 | 修正後 |
|---|---|---|
| `b` のデフォルト値 | `0` | `1` |
| ゼロガード | なし | `b == 0` の場合に HTTP 400 を返す |

1. **デフォルト値を `1` に変更** — パラメータ省略時でも安全に動作します
2. **明示的なゼロチェックを追加** — `b=0` を明示的に渡した場合もエラーレスポンス(HTTP 400)を返すことで、誤用を防ぎます

### テスト結果
既存の4テストすべてが通過しました(`test_calculate_default_params` は以前バグのために失敗していましたが、今回の修正で通過)。...

Changed Files

app.py


This PR was automatically generated by Red Codens using Claude Code CLI

Auto-generated by Red Codens using Claude Code CLI

Error Type: ZeroDivisionError
Fixed Files: app.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant