Skip to content

Commit 58b9581

Browse files
fix(export): move ErrorCode to models to avoid Flask in utils (PR #73)
Extract ErrorCode to models/error_codes.py so export_engine no longer transitively imports Flask via api. Document export-phase exc handling.
1 parent 2dc2d25 commit 58b9581

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

api/error_codes.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
"""Stable machine-readable error codes for API JSON error responses."""
1+
"""HTTP error envelope helpers; :class:`ErrorCode` lives in :mod:`models.error_codes`."""
22

33
from __future__ import annotations
44

5-
from enum import StrEnum
6-
75
from flask import Response, jsonify
86

7+
from models.error_codes import ErrorCode
98

10-
class ErrorCode(StrEnum):
11-
SEARCH_INVALID_LIMIT = "SEARCH_INVALID_LIMIT"
12-
INVALID_PATH = "INVALID_PATH"
13-
SESSION_NOT_FOUND = "SESSION_NOT_FOUND"
14-
INVALID_REQUEST_BODY = "INVALID_REQUEST_BODY"
15-
INVALID_SINCE_MODE = "INVALID_SINCE_MODE"
16-
PARSE_ERROR = "PARSE_ERROR"
17-
EXPORT_NOTHING_TO_EXPORT = "EXPORT_NOTHING_TO_EXPORT"
18-
EXPORT_ALL_FAILED = "EXPORT_ALL_FAILED"
19-
INTERNAL_ERROR = "INTERNAL_ERROR"
9+
__all__ = ["ErrorCode", "error_response"]
2010

2111

2212
def error_response(

models/error_codes.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Stable machine-readable error codes (shared by API and utils; no Flask dependency)."""
2+
3+
from __future__ import annotations
4+
5+
from enum import StrEnum
6+
7+
8+
class ErrorCode(StrEnum):
9+
SEARCH_INVALID_LIMIT = "SEARCH_INVALID_LIMIT"
10+
INVALID_PATH = "INVALID_PATH"
11+
SESSION_NOT_FOUND = "SESSION_NOT_FOUND"
12+
INVALID_REQUEST_BODY = "INVALID_REQUEST_BODY"
13+
INVALID_SINCE_MODE = "INVALID_SINCE_MODE"
14+
PARSE_ERROR = "PARSE_ERROR"
15+
EXPORT_NOTHING_TO_EXPORT = "EXPORT_NOTHING_TO_EXPORT"
16+
EXPORT_ALL_FAILED = "EXPORT_ALL_FAILED"
17+
INTERNAL_ERROR = "INTERNAL_ERROR"

utils/export_engine.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from datetime import date, datetime, timezone
1010
from typing import Any, Callable, Literal, Protocol
1111

12-
from api.error_codes import ErrorCode
12+
from models.error_codes import ErrorCode
1313
from models.project import ProjectDict, SessionListItemDict
1414
from models.session import SessionDict, SessionMetadataDict
1515
from models.stats import SessionStatsDict
@@ -74,7 +74,11 @@ def failure_code_for_exception(
7474
*,
7575
phase: Literal["parse", "export"] = "parse",
7676
) -> ErrorCode:
77-
"""Map an export exception to a stable :class:`ErrorCode`."""
77+
"""Map an export exception to a stable :class:`ErrorCode`.
78+
79+
Export-phase failures always map to ``INTERNAL_ERROR``; ``exc`` is not
80+
inspected on that path (no per-type export codes yet).
81+
"""
7882
if phase == "export":
7983
return ErrorCode.INTERNAL_ERROR
8084
if isinstance(exc, EXPORT_ERRORS):

0 commit comments

Comments
 (0)