7Source-validation exception types for the AuthoredSource engine.
11Carry the granular ``SRC_*`` failure code (Registry Source & Storage Spec V0.22
12§10) on every condition the scanner / canonical loader / hashing layer raises,
13so the ``regenerate`` pipeline (P1.4) can assemble the JSON error envelope and
14operators/CI can branch on the exact cause.
18- Define ``SourceError`` (base) carrying ``code``/``records``/``hint``.
19- Define ``SourceScanError`` (tree cannot be enumerated; ``scan_error``).
20- Define ``SourceValidationError`` (a record/path/canonicalisation failure).
21- Expose the P1.3-emitted ``SRC_*`` code constants.
27 L2 - error construction
28 L3 - offending record context
29 L4 - code/hint assembly
33- ``code`` is one of the durable §10 ``SRC_*`` strings (NOT a class name).
34- ``records`` is a deterministically ordered list of offending file/field refs.
35- P1.4 owns the full envelope assembly + the complete code enum; this module
36 owns only the exception classes the P1.3 surface raises.
40- oc_diagnostics (structured debug logging via _dbg)
42from __future__
import annotations
44from typing
import Optional, Sequence
46from oc_diagnostics
import _dbg
48_dbg(
"OC_CHAT.MAIN",
"module",
"loaded", 4)
51SRC_SCAN_FAILED =
"SRC_SCAN_FAILED"
52SRC_UNKNOWN_FILE =
"SRC_UNKNOWN_FILE"
53SRC_BAD_PHASE_PATH =
"SRC_BAD_PHASE_PATH"
54SRC_DUP_OR_STEM_MISMATCH =
"SRC_DUP_OR_STEM_MISMATCH"
55SRC_BAD_YAML =
"SRC_BAD_YAML"
56SRC_BAD_YAML_FEATURE =
"SRC_BAD_YAML_FEATURE"
57SRC_STRICT_TYPE =
"SRC_STRICT_TYPE"
58SRC_NOT_CANONICAL =
"SRC_NOT_CANONICAL"
59SRC_BAD_QUERY_PARAMS =
"SRC_BAD_QUERY_PARAMS"
63 """Base for every AuthoredSource failure, carrying the §10 envelope fields."""
70 records: Optional[Sequence[str]] =
None,
71 hint: Optional[str] =
None,
75 self.
records: list[str] = list(records)
if records
else []
80 """The source tree cannot be fully enumerated/read (perm/symlink/encoding).
82 Carries ``scan_error = {path, os_error}``; the envelope's
83 ``raw_source_tree_hash`` is ``null`` for this class (§10).
92 hint: Optional[str] =
None,
94 super().
__init__(message, code=SRC_SCAN_FAILED, records=[path], hint=hint)
99 """A record/path/canonicalisation failure (unknown file, bad path shape,
100 bad YAML, strict-type rejection, non-canonical bytes, bad query params)."""
None __init__(self, str message, *, str code, Optional[Sequence[str]] records=None, Optional[str] hint=None)
None __init__(self, str message, *, str path, str os_error, Optional[str] hint=None)