oc_chat
Loading...
Searching...
No Matches
errors.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# oc_chat/registry/source/errors.py
4
5# OCT-LINT: disable=tests_exist reason="Covered by oc_chat/tests/registry/source/test_scanner.py"
6"""
7Source-validation exception types for the AuthoredSource engine.
8
9Purpose
10-------
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.
15
16Responsibilities
17----------------
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.
22
23Diagnostics
24-----------
25Domain: OC_CHAT.MAIN
26Levels:
27 L2 - error construction
28 L3 - offending record context
29 L4 - code/hint assembly
30
31Contracts
32---------
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.
37
38Dependencies
39------------
40- oc_diagnostics (structured debug logging via _dbg)
41"""
42from __future__ import annotations
43
44from typing import Optional, Sequence
45
46from oc_diagnostics import _dbg
47
48_dbg("OC_CHAT.MAIN", "module", "loaded", 4)
49
50# §10 SRC_* codes emitted by the P1.3 surface (scanner / canonical / hashing).
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"
60
61
62class SourceError(Exception):
63 """Base for every AuthoredSource failure, carrying the §10 envelope fields."""
64
66 self,
67 message: str,
68 *,
69 code: str,
70 records: Optional[Sequence[str]] = None,
71 hint: Optional[str] = None,
72 ) -> None:
73 super().__init__(message)
74 self.code = code
75 self.records: list[str] = list(records) if records else []
76 self.hint = hint
77
78
80 """The source tree cannot be fully enumerated/read (perm/symlink/encoding).
81
82 Carries ``scan_error = {path, os_error}``; the envelope's
83 ``raw_source_tree_hash`` is ``null`` for this class (§10).
84 """
85
87 self,
88 message: str,
89 *,
90 path: str,
91 os_error: str,
92 hint: Optional[str] = None,
93 ) -> None:
94 super().__init__(message, code=SRC_SCAN_FAILED, records=[path], hint=hint)
95 self.scan_error = {"path": path, "os_error": os_error}
96
97
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)
Definition errors.py:72
None __init__(self, str message, *, str path, str os_error, Optional[str] hint=None)
Definition errors.py:93