Repository navigation
Expand file tree
/
Copy patherrors.py
More file actions
374 lines (348 loc) · 13.8 KB
/
Copy patherrors.py
File metadata and controls
374 lines (348 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
from __future__ import annotations
import os
from types import FunctionType
from gflow_cli._errors.auth import (
AuthBrowserRejectedError as AuthBrowserRejectedError,
)
from gflow_cli._errors.auth import (
AuthLoginTimeoutError,
AuthMissingError,
IdentityRecheckPendingError,
SecurityError,
)
from gflow_cli._errors.auth import (
BrowserSessionClosedError as BrowserSessionClosedError,
)
from gflow_cli._errors.base import (
CHARGED_VALUES,
NEXT_ACTION_VALUES,
RETRY_ACTIONS,
Charged,
GFlowError,
NextAction,
ProblemDetails,
nothing_submitted,
outcome_members,
)
from gflow_cli._errors.config import (
BrowserEngineUnavailableError,
ConfigurationError,
ModelModeIncompatibilityError,
OwnerEvidence,
ProfileAccessError,
VideoModelSelectionError,
)
from gflow_cli._errors.config import (
ProfileEngineDowngradeError as ProfileEngineDowngradeError,
)
from gflow_cli._errors.config import (
ProfileLockedError as ProfileLockedError,
)
from gflow_cli._errors.flow import (
CreditCapExceededError,
ExtendUnavailableError,
FlowAccessUnavailableError,
FlowAccountChooserError,
FlowAgentUiError,
FlowAppError,
FlowHostMigratedError,
MediaAttributionError,
MediaUploadRejectedError,
MentionIndexUnavailableError,
QueueSchemaError,
RecaptchaError,
ReferenceNotFoundError,
ServerCancelUnavailableError,
TaskCancelledError,
TaskNotFoundError,
UiModeUnavailableError,
UiSelectorDriftError,
UpscaleUnavailableError,
)
from gflow_cli._errors.flow import (
InsufficientCreditsError as InsufficientCreditsError,
)
from gflow_cli._errors.flow_api import (
CONTENT_SAFETY_REASONS,
AisandboxAuthError,
AuthExpiredError,
ContentPolicyError,
FlowApiError,
MediaDownloadError,
NetworkError,
RateLimitError,
RpcResponseUnavailableError,
SceneConcatError,
TransportTimeoutError,
WafRejectionError,
WireFormatError,
classify_content_safety,
)
from gflow_cli._errors.local import (
BatchIntegrityError,
BatchPartialError,
ChainManifestError,
ChainPartialError,
DataIntegrityError,
DataMigrationError,
DataStoreError,
FrameExtractionError,
SyncPartialError,
VideoAssemblyError,
)
from gflow_cli._errors.local import (
VideoProcessingError as VideoProcessingError,
)
# The classes and functions live in gflow_cli._errors but keep gflow_cli.errors as their
# public identity: reprs, tracebacks, pickling and the client facade contract name it
# (#1715). Limit: inspect.getsource() on a moved class looks in this file, so it raises
# OSError or returns unrelated lines; functions are unaffected (their code names the file).
def _keep_public_identity() -> None:
for obj in list(globals().values()):
if isinstance(obj, type | FunctionType) and obj.__module__.startswith("gflow_cli._errors."):
obj.__module__ = __name__
_keep_public_identity()
__all__ = [
"CHARGED_VALUES",
"CONTENT_SAFETY_REASONS",
"EXIT_CODE_MAP",
"NEXT_ACTION_VALUES",
"RETRYABLE_ERRORS",
"RETRY_ACTIONS",
"Charged",
"NextAction",
"AisandboxAuthError",
"AuthExpiredError",
"AuthLoginTimeoutError",
"AuthMissingError",
"BatchIntegrityError",
"BatchPartialError",
"BrowserEngineUnavailableError",
"ChainManifestError",
"ChainPartialError",
"ConfigurationError",
"ContentPolicyError",
"CreditCapExceededError",
"DataIntegrityError",
"DataMigrationError",
"DataStoreError",
"ExtendUnavailableError",
"FlowAgentUiError",
"FlowApiError",
"FlowAppError",
"FlowAccessUnavailableError",
"FlowAccountChooserError",
"FlowHostMigratedError",
"FrameExtractionError",
"GFlowError",
"IdentityRecheckPendingError",
"MediaAttributionError",
"MediaUploadRejectedError",
"ReferenceNotFoundError",
"MentionIndexUnavailableError",
"ModelModeIncompatibilityError",
"MediaDownloadError",
"NetworkError",
"OwnerEvidence",
"ProblemDetails",
"ProfileAccessError",
"QueueSchemaError",
"RateLimitError",
"RecaptchaError",
"RpcResponseUnavailableError",
"SceneConcatError",
"SecurityError",
"ServerCancelUnavailableError",
"SyncPartialError",
"TaskCancelledError",
"TaskNotFoundError",
"TransportTimeoutError",
"UiModeUnavailableError",
"UiSelectorDriftError",
"UpscaleUnavailableError",
"VideoModelSelectionError",
"VideoAssemblyError",
"WafRejectionError",
"WireFormatError",
"active_exit_code",
"active_exit_code_mode",
"classify_content_safety",
"exit_code_for",
"is_retryable",
"legacy_exit_code_for",
"outcome_members",
"nothing_submitted",
]
# EXIT_CODE_MAP — most-specific class FIRST per isinstance walk semantics.
# Subclasses inherit their parent's exit code if they don't have their own
# entry. New entries MUST go BEFORE their parent class in this dict.
EXIT_CODE_MAP: dict[type[GFlowError], int] = {
ChainPartialError: 21,
FrameExtractionError: 20,
DataMigrationError: 16,
DataIntegrityError: 16,
DataStoreError: 16,
BrowserSessionClosedError: 15,
AuthBrowserRejectedError: 14,
AuthLoginTimeoutError: 12,
SecurityError: 13,
AuthMissingError: 8,
TransportTimeoutError: 9,
WafRejectionError: 10,
# UpscaleUnavailableError (issue #171): tier-gated 4K upscale 403, DISTINCT
# from WafRejectionError's 10 even though both are HTTP 403. Direct GFlowError
# subclass, so unconstrained by the ordering invariant.
UpscaleUnavailableError: 22,
# ServerCancelUnavailableError (#1198): shares 22, "capability unavailable, do not
# retry"; the #1202 stable core keeps 22 as is. Direct GFlowError subclass.
ServerCancelUnavailableError: 22,
ExtendUnavailableError: 35,
# UiSelectorDriftError (issue #183): Flow UI changed, selector probe failed.
# Direct GFlowError subclass; exit 23 lets scripts distinguish "UI drifted"
# from generic error (1) without parsing stderr.
UiSelectorDriftError: 23,
InsufficientCreditsError: 37,
CreditCapExceededError: 45,
# ModelModeIncompatibilityError + VideoModelSelectionError BEFORE
# ConfigurationError (their parent) so the isinstance walk lands on 17/18,
# not 11. Per [[exit-code-map-ordering-invariant-test-pitfall]].
ModelModeIncompatibilityError: 17,
VideoModelSelectionError: 18,
# BrowserEngineUnavailableError (Patchright engine opt-in): BEFORE
# ConfigurationError (its parent) so the isinstance walk lands on 24, not 11.
BrowserEngineUnavailableError: 24,
FlowAgentUiError: 25,
FlowAppError: 31,
# FlowHostMigratedError (#639): Flow served the migrated
# flow.google.com frontend for a request not ported to it yet. Direct
# GFlowError subclass; exit 36 lets scripts distinguish "wrong Flow
# frontend" (per-account, not retryable) from genuine selector drift
# (23), which it used to masquerade as.
FlowHostMigratedError: 36,
# FlowAccountChooserError: Google Flow landed on account chooser
# and the recorded account row could not be selected automatically.
# Direct GFlowError subclass; exit 38 distinguishes account chooser stall
# from generic errors (1) without parsing stderr.
FlowAccountChooserError: 38,
# FlowAccessUnavailableError: Flow rendered its unavailable screen — this
# account has no Flow entitlement. Exit 39 rather than 3/8 (auth) because a
# re-login cannot fix it, and rather than 23 because nothing drifted: the
# app loaded and routed to a component built for exactly this state.
FlowAccessUnavailableError: 39,
# UiModeUnavailableError (issue #299): a command's required arm (--ui-mode /
# inferred) couldn't be reached after a best-effort switch. Direct GFlowError
# subclass — retryable policy abort, distinct from FlowAgentUiError (25).
UiModeUnavailableError: 28,
# MediaAttributionError (issue #281): generated media could not be
# reliably attributed (agentic DOM-scrape ambiguity, or a downstream
# already-recorded check). Direct GFlowError subclass; exit 26 lets
# scripts distinguish "wrong/ambiguous media" from a generic error (1).
MediaAttributionError: 26,
# MediaUploadRejectedError (issue #287): Flow's upload endpoint refused the
# input file (uploadImage 4xx). Direct GFlowError subclass; exit 27 lets
# scripts branch on "re-encode the input image" vs generic error (1).
MediaUploadRejectedError: 27,
# ReferenceNotFoundError (#493 recon): a reference name identified an asset the
# project picker does not offer. Direct GFlowError subclass; exit 32 lets scripts
# distinguish "that name is not in the picker" from a UI drift error (23),
# which is what this previously masqueraded as via a raw TimeoutError.
ReferenceNotFoundError: 32,
# MentionIndexUnavailableError: an @mention was present but the catalog
# source needed to resolve it (character or media) failed to load.
# Direct GFlowError subclass; exit 29 lets scripts distinguish "the
# catalog is unreachable" from an unknown-mention ConfigurationError (11).
MentionIndexUnavailableError: 29,
# QueueSchemaError (Task C2): a worker-queue payload's schema_version is
# unknown, or its fields fail validation against the typed request DTOs.
# Direct GFlowError subclass; exit 30 lets scripts distinguish "the queue
# row is malformed/from an incompatible version" from generic error (1).
QueueSchemaError: 30,
# SyncPartialError (#543): `gflow data sync --names` wrote some projects
# but not all. Direct GFlowError subclass; exit 34 lets scripts distinguish
# "partially synced, just re-run" from generic error (1).
SyncPartialError: 34,
ConfigurationError: 11,
AuthExpiredError: 3,
RateLimitError: 4,
ContentPolicyError: 5,
NetworkError: 6,
WireFormatError: 7,
SceneConcatError: 19,
# FlowApiError omitted — falls through to default 1
}
#: Mapping from legacy exit codes (4-9) to the stable exit-code core (mode 2, #1202).
#: Codes 0, 1, 2, 3, 130 and 10-39 are unchanged.
#: Code 4 is reserved for "accepted, still running" (emitted by nothing in release N).
#: Codes 5-9 are reserved. Codes 40-63 are the range for specific causes.
_CORE_V2_EXIT_CODES: dict[int, int] = {
4: 40, # RateLimitError
5: 41, # ContentPolicyError
6: 42, # NetworkError
7: 43, # WireFormatError
8: 3, # AuthMissingError (AuthExpiredError is already 3)
9: 44, # TransportTimeoutError
}
def active_exit_code_mode() -> int:
"""2 when ``GFLOW_CLI_EXIT_CODES=2`` (environment or ``.env``), else 1 (#1202)."""
try:
from gflow_cli.config import get_settings # lazy: config must not import errors early
value = get_settings().exit_codes
except Exception: # noqa: BLE001 - a broken config must never break the error path
value = os.environ.get("GFLOW_CLI_EXIT_CODES")
return 2 if (value or "").strip() == "2" else 1
def active_exit_code(legacy: int) -> int:
"""The legacy code *legacy* translated to the active mode (#1202)."""
return _CORE_V2_EXIT_CODES.get(legacy, legacy) if active_exit_code_mode() == 2 else legacy
def legacy_exit_code_for(exc: GFlowError) -> int:
"""Return the legacy exit code for *exc* via isinstance-walk on ``EXIT_CODE_MAP``.
Iteration order matters: subclasses inherit the parent class's code only
if they don't have their own entry, and the dict is ordered
most-specific-first.
"""
for cls, code in EXIT_CODE_MAP.items():
if isinstance(exc, cls):
return code
return 1
def exit_code_for(exc: GFlowError) -> int:
"""Return the process exit code for *exc* in the active mode (#1202)."""
return active_exit_code(legacy_exit_code_for(exc))
# Transient failures the caller can retry without operator intervention — WAF
# bounce, rate-limit/quota, transport timeout, network blip, a dropped browser
# session, a Flow web-app crash (31), or an agentic-cohort flap (25). Everything
# else (auth/content-policy/config/security) is terminal: retrying the identical
# request will fail the same way. Single source of truth for the CLI --json, MCP,
# and worker error envelopes — never fork a private copy of this list.
RETRYABLE_ERRORS: tuple[type[GFlowError], ...] = (
WafRejectionError,
RateLimitError,
TransportTimeoutError,
NetworkError,
BrowserSessionClosedError,
FlowAppError,
FlowAgentUiError,
# #639 is deliberately NOT here. FlowHostMigratedError used to be listed on
# the belief that the migration "flaps per page load"; it is a server-assigned
# per-account boolean (5/5, 7/7 measured 2026-09-04), so a retry into it is
# a doomed attempt. Exit 36 stays; the machine flag no longer invites the loop.
# #299: the cohort is server-assigned per page load and flaps — the
# documented remediation for exit 28 IS "retry"; the machine flag must
# agree with the docs.
UiModeUnavailableError,
# #543: sync is idempotent — the documented remediation for exit 34 IS
# "re-run"; the machine flag must agree with the docs.
SyncPartialError,
)
def is_retryable(exc: GFlowError) -> bool:
"""Shared retry classification consumed by every machine-readable error surface.
The class answer (``RETRYABLE_ERRORS``) unless the raise site overrode it — see
``GFlowError.retryable``.
``isinstance(..., bool)`` rather than a truthiness test, deliberately: a
``MagicMock`` answers every ``getattr`` with a truthy child mock, so
``if override is not None`` would silently report **every** mocked error as
retryable and no assertion in the suite would notice
(memory ``magicmock-truthy-getattr-silences-guards``).
"""
override = getattr(exc, "retryable", None)
if isinstance(override, bool):
return override
return isinstance(exc, RETRYABLE_ERRORS)