Skip to content

Add machine-readable Code enum to flow.Error - #8321

Open
youdie006 wants to merge 2 commits into
mitmproxy:mainfrom
youdie006:feat/flow-error-type-enum
Open

Add machine-readable Code enum to flow.Error#8321
youdie006 wants to merge 2 commits into
mitmproxy:mainfrom
youdie006:feat/flow-error-type-enum

Conversation

@youdie006

Copy link
Copy Markdown

Closes #4554.

Adds a machine-readable category to flow.Error so consumers can distinguish interrupted connections, timeouts, and protocol errors, while the human-facing msg is unchanged (as the issue requests).

  • New nested Error.Code enum: GENERIC (default) / KILLED / CONNECTION / TIMEOUT / PROTOCOL. Nested to avoid colliding with the existing HTTP ErrorCode int enum.
  • The code field is placed after timestamp to preserve positional back-compat (Error(msg, ts)), and kill() sets KILLED. Codes are set at categorizable construction sites (connection-open failures -> CONNECTION, header validation / protocol errors -> PROTOCOL); GENERIC elsewhere.
  • Flow format bumped 21 -> 22 with a convert_21_22 migration so existing .mitm files still load.

Design follows the issue and the review on the earlier (abandoned) #5662: a GENERIC default instead of a required arg (no breaking change), KILLED unified into the enum, and the format migration.

Test plan

Added test_flow.py::TestError cases (default/explicit/round-trip) and test_compat.py::test_convert_21_22 (red->green). test_flow.py + test_compat.py + test_io.py -> 33 passed; proxy layer tests -> 259 passed. ruff + mypy clean.


AI disclosure: this PR was drafted with Claude Code (AI-assisted). Tests were run red->green locally (test_flow + test_compat independently re-verified: 21 passed).

youdie006 and others added 2 commits July 13, 2026 11:25
Add a nested Error.Code enum (generic/killed/connection/timeout/protocol) so
consumers can distinguish error categories while the human-facing msg is
unchanged. Set the code at categorizable construction sites and bump the flow
format with a 21->22 migration for back-compat.
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.

Add error type / code enum

1 participant