-
-
Notifications
You must be signed in to change notification settings - Fork 40
check_doc_gate.py: a broken/unparseable config exits 1 identically to a real violation #2306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,6 +37,13 @@ | |||||||||||||||||||||
| DEFAULT_CONFIG = REPO_ROOT / "docs" / "doc-gate.toml" | ||||||||||||||||||||||
| DEFAULT_TRAILER = "Docs-Reviewed:" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Exit codes: 0 clean, 1 a doc-gate violation, 2 a config/usage error | ||||||||||||||||||||||
| # (broken, missing, or unparseable config). Distinct so a misconfigured gate | ||||||||||||||||||||||
| # is never mistaken for a real documentation-drift violation. | ||||||||||||||||||||||
| EXIT_OK = 0 | ||||||||||||||||||||||
| EXIT_VIOLATION = 1 | ||||||||||||||||||||||
| EXIT_CONFIG_ERROR = 2 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # A path-like token: one of the four known repo prefixes followed by a run of | ||||||||||||||||||||||
| # non-whitespace / non-quoting characters. The negative lookbehind stops us | ||||||||||||||||||||||
| # matching a prefix that is actually embedded inside a larger path (e.g. the | ||||||||||||||||||||||
|
|
@@ -254,10 +261,10 @@ def get_trailer(config: dict) -> str: | |||||||||||||||||||||
| def _report(failures: list[str]) -> int: | ||||||||||||||||||||||
| if not failures: | ||||||||||||||||||||||
| print("doc-gate: clean") | ||||||||||||||||||||||
| return 0 | ||||||||||||||||||||||
| return EXIT_OK | ||||||||||||||||||||||
| for failure in failures: | ||||||||||||||||||||||
| print(f"DOC-GATE FAIL: {failure}") | ||||||||||||||||||||||
| return 1 | ||||||||||||||||||||||
| return EXIT_VIOLATION | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def main(argv: list[str] | None = None) -> int: | ||||||||||||||||||||||
|
|
@@ -273,7 +280,11 @@ def main(argv: list[str] | None = None) -> int: | |||||||||||||||||||||
| group.add_argument("--base", help="Compare <base>...HEAD (CI / commit-msg)") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| args = parser.parse_args(argv) | ||||||||||||||||||||||
| config = load_config(args.config) | ||||||||||||||||||||||
| try: | ||||||||||||||||||||||
| config = load_config(args.config) | ||||||||||||||||||||||
| except (tomllib.TOMLDecodeError, OSError) as e: | ||||||||||||||||||||||
| print(f"doc-gate: config error: {args.config}: {e}", file=sys.stderr) | ||||||||||||||||||||||
| return EXIT_CONFIG_ERROR | ||||||||||||||||||||||
|
Comment on lines
+283
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
python - <<'PY'
import io
import tomllib
try:
tomllib.load(io.BytesIO(b"\xff"))
except UnicodeDecodeError:
print("confirmed")
else:
raise SystemExit("expected UnicodeDecodeError")
PYRepository: jaylfc/taOS Length of output: 159 🏁 Script executed: #!/bin/bash
set -euo pipefail
python - <<'PY'
import io, tomllib
for value in (b"\xff", b"\x80", b"\x80\x80\x80"):
try:
tomllib.load(io.BytesIO(value))
except Exception as exc:
print(type(exc).__name__, bool(isinstance(exc, tomllib.TOMLDecodeError)), bool(isinstance(exc, UnicodeDecodeError)))
else:
print("parsed OK")
PY
printf '\n--- scripts/check_doc_gate.py context ---\n'
sed -n '250,300p' scripts/check_doc_gate.py
printf '\n--- config error tests/usages ---\n'
rg -n "EXIT_CONFIG_ERROR|load_config|TOMLDecodeError|UnicodeDecodeError|bad\.write_bytes|config error" scripts -SRepository: jaylfc/taOS Length of output: 2804 Handle invalid UTF-8 as a configuration error.
Proposed fix- except (tomllib.TOMLDecodeError, OSError) as e:
+ except (tomllib.TOMLDecodeError, UnicodeDecodeError, OSError) as e:📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if args.command == "invariants": | ||||||||||||||||||||||
| files_to_scan = config.get("invariants", {}).get("referenced_paths_scan", []) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1. Schema errors still crash
🐞 Bug☼ ReliabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools