From 8be6993d1496b0cec62c3a485519f6f915a62ecf Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 13 May 2026 20:45:14 +0000 Subject: doc-linter: narrow argv parsing exception scope to (IndexError, SyntaxError, ValueError) CodeRabbit / Ruff BLE001: the previous 'except Exception as e:' on the explicit-file-list path caught any error, masking runtime failures from handle_file_action() as silent fallback behavior. Only input validation errors from ast.literal_eval(sys.argv[1]) should trigger the fallback walk. Refactor: - Wrap only the parse step in try/except, catching just IndexError (missing argv[1]), SyntaxError (malformed literal), and ValueError (non-literal input). - On parse failure, set files = None and dispatch to the DOCS_ROOT walk via an explicit 'else' branch. - On parse success, run the file loop outside the try so any errors from handle_file_action() propagate normally and CI fails loudly. Also drops the unused 'as e' (Ruff BLE001 noise) and the implicit catch of TypeError (e.g. ast.literal_eval('42') returns an int and 'for file in 42:' would have been silently swallowed -> fallback walk; now it raises clearly). Verified scenarios: - explicit file list (CI normal path) -> exit 0. - no argv -> IndexError caught -> walks DOCS_ROOT. - malformed argv ('not-a-list') -> SyntaxError caught -> walks DOCS_ROOT. - explicit list with a non-existent file -> FileNotFoundError propagates (previously silently triggered a fallback walk). - explicit list with a non-list literal ('42') -> TypeError propagates (programming error stays visible). --- scripts/doc-linter.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/doc-linter.py b/scripts/doc-linter.py index b1977f84..8e74600f 100644 --- a/scripts/doc-linter.py +++ b/scripts/doc-linter.py @@ -250,8 +250,16 @@ def main(): """Entry point: lint the changed-file list from argv, or fall back to walking `docs/`.""" bool_error = True print('start') + # Only the argv-parsing step is wrapped in try/except. Errors raised by + # handle_file_action() must propagate so CI failures stay visible instead + # of silently triggering a full docs/ walk. try: files = ast.literal_eval(sys.argv[1]) + except (IndexError, SyntaxError, ValueError): + # No argv or malformed list -> fall back to walking DOCS_ROOT. + files = None + + if files is not None: for file in files: if ( file.endswith(SUPPORTED_EXTS) @@ -260,7 +268,7 @@ def main(): ): if handle_file_action(file) is False: bool_error = False - except Exception as e: + else: for root, _dirs, files in os.walk(DOCS_ROOT): path = root.split(os.sep) for file in files: -- cgit v1.2.3