Repository navigation
fix(config): a config file that is not valid YAML stops the load with an error that quotes none of its text - #2468
Conversation
Test resultsTargeted tests on the branch after the rebase onto Before the second rebase,
Fail-to-pass
|
Plan the change folder for #1468. A config file that is not valid YAML stops the load of the settings with an error that names the file, the line and the column, and that quotes no text of the file.
… load with no file text The load of the settings must fail with ConfigurationError that names the file, the line and the column. The error, its chain and the output must hold no text of the file. `devops config get` must print the error on one line, exit 1 and log no record with a traceback. Refs #1468
… no text of the file The load of the settings let a PyYAML error go up. Its message quotes the line where the parser stopped, and the `buffer` of its mark holds the full text of the file. Thus each command that loads the settings printed that line, which can hold a pasted credential. - `_read_config_layers` reads each config file through `_read_config_file`. A file that is not valid YAML raises ConfigurationError with the message `Cannot load the settings: <file> is not valid YAML (<error type>) at line <n>, column <n>.` The error is raised after the `except` block, so it has no cause and no context. - `devops config get` reports a ConfigurationError from the load on one line and exits 1, through `exit_on_error`, as `devops config unset` does. - `main._delegate` raises the non-zero exit of a command in the `else` clause of its `try`. Before, its own `except Exception` caught that exit, counted the command a second time and logged `Command '<name>' failed: <code>` with a traceback. With no logging handler, Python printed that traceback on stderr. Refs #1468
The knowledge base gives the message of the error and tells why it quotes no text of the file. The PyYAML example raises an error with the type and the position of the PyYAML error, and no text of the document. Refs #1468
…le that is not UTF-8, to stop the load with no file text The safe loader of PyYAML raises ValueError, KeyError or AttributeError for a tagged value that it cannot build, and the message of the error quotes the value. A file that is not UTF-8 raises UnicodeDecodeError, whose object attribute holds the bytes of the file. The tests also format the traceback with the local variables of each frame.
…is not UTF-8, stops the load with no file text The safe loader of PyYAML raises ValueError, KeyError, IndexError or AttributeError for a tagged value that it cannot build, such as !!int <text>, and the message quotes the value. These errors are not yaml.YAMLError, so they went up as they were. A file that is not UTF-8 raised UnicodeDecodeError, whose object attribute holds the bytes of the file. _read_config_file now gives the same ConfigurationError for each error of the read and the parse but OSError. The spec delta puts the config get scenario in its own requirement and no longer says that the command prints nothing more, because the atexit hook prints the elapsed time.
…tionError and keeps no mark in the raising frame The example kept the PyYAML mark in a local variable of the frame that raised the error, and the buffer of the mark holds the full text of the file. A traceback that shows local variables then showed that text. The example raised a bare ValueError, which CONTRIBUTING.md prohibits. It now reads the position in a helper function, catches each error but OSError, and raises ConfigurationError, as config/settings.py::_read_config_file does. The settings page also names the error for a tagged value that PyYAML cannot build and for a file that is not UTF-8.
…rds its exit code and logs no record The exit of a command that returns a non-zero code moved to the else clause of the try in main._delegate. Before, except Exception caught that exit: it counted the command a second time, recorded the exit code 1, and logged the exit with a traceback. No test held the count or the exit code, so the exit could go back into the try with no failed test. The change now carries a command-telemetry delta, and docs/TELEMETRY.md and the design say that devops-cli logs no record for that exit.
…o deep to stop the load with no file text
…ad by name, not Exception
… of the load by name
4d518fc to
907ae10
Compare
Fix round 1: Tests & CoverageThe The fix keeps the ceiling. The branch is rebased onto Targeted tests:
|
🤖 I have created a release *beep* *boop* --- ## [0.10.0](v0.9.0...v0.10.0) (2026-10-28) ### Features * **review:** devops review intake hands the findings of a session on merged code to roadmap intake ([#2455](#2455)) ([a5c7b82](a5c7b82)) * **security:** devops k8s audit runs Popeye in the tool sandbox with a kube-api network profile that only reads the API server ([#2467](#2467)) ([e02c3fb](e02c3fb)) * **security:** the App's installation tokens carry only the permissions the roadmap jobs use ([#2482](#2482)) ([9599ef2](9599ef2)), closes [#2473](#2473) ### Bug Fixes * **config:** a config file that is not valid YAML stops the load with an error that quotes none of its text ([#2468](#2468)) ([91fe5dc](91fe5dc)) * **config:** config set reports an unknown key as unknown, not as a key that needs a value ([#2465](#2465)) ([8b650a6](8b650a6)) * **devcontainer:** run the checkout's devops in devcontainer terminals ([#2460](#2460)) ([abd2d41](abd2d41)) * **k8s:** loki runs from the grafana-community chart on loki 3.7.9, out of reach of CVE-2026-21729 ([#2470](#2470)) ([96c50c9](96c50c9)) * **security:** a credential keyword at the end of a line no longer masks the first word of the next line ([#2461](#2461)) ([b754a73](b754a73)) * **security:** a credential value is masked also when the next line starts with a parenthesis ([#2477](#2477)) ([ece25ca](ece25ca)), closes [#2471](#2471) * **security:** pin kubeconform and replace Checkov with Trivy's misconfiguration scan ([#2464](#2464)) ([960e357](960e357)) * **security:** refuse GCONV_PATH, SHELLOPTS, BASHOPTS and PS4 from a caller, and archive the merged security changes ([#2453](#2453)) ([1f9231d](1f9231d)) ### Code Refactoring * **ai:** chat_structured is the one structured-output path ([#2452](#2452)) ([3509732](3509732)) * **github:** pr check-readiness reads one merge-readiness verdict from github/ ([#2456](#2456)) ([16442c4](16442c4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
load_settingsreads the global config file and the project config file through one helper,_read_config_fileinsrc/devops_cli/config/settings.py. When a file is not valid YAML, the helper raisesConfigurationErrorwith the messageCannot load the settings: <file> is not valid YAML (<error type>) at line <n>, column <n>.The line and the column come from theproblem_markof the PyYAML error. The message quotes no text of the file.Before this change, each command that loads the settings let the
yaml.YAMLErrorgo up. The message of that error quotes the line where the parser stopped, and a malformed line is where a pasted credential usually is. Thus stderr showed that line in the error text and in each traceback. #1022 fixed this fordevops config audit-keysonly.The helper gives the same message for the other errors of the read and the parse, and catches each by name:
(yaml.YAMLError, ValueError, LookupError, AttributeError, RecursionError). The safe loader of PyYAML raisesValueError,KeyError,IndexErrororAttributeErrorfor a tagged value that it cannot build, such as!!int <text>, and the message of that error can quote the value. It raisesRecursionErrorfor a document that nests too deep. A file that is not UTF-8 raisesUnicodeDecodeError, which holds the bytes of the file. These errors have no mark, so their message has no line and no column. A test file holds a case for each type. The helper does not catchException, because the swallowed-failures ratchet refuses a new blindexceptinsrc/. AnOSErrornames only the file, so it goes up as before.The helper raises the error after its
exceptblock, so the error has no__cause__and no__context__. TheMarkof a PyYAML error holds the full text of the file in itsbuffer, andraise ... from Noneonly hides__context__from the traceback. Thus no traceback or log record holds the PyYAML error.devops config getloads the settings insideexit_on_error(ConfigurationError), asdevops config unsetdoes. It prints the error on one line, prints no traceback, and exits 1.main._delegateraises the exit of a command that returns a non-zero exit code in theelseclause of itstry. Before, it raised that exit inside thetry, and its ownexcept Exceptioncaught it, becausetyper.Exitis aRuntimeError. That clause counted the command a second time indevops_cli_command_total, setcli.exit_codeto 1, and loggedCommand '<name>' failed: <code>with a traceback. When the settings do not load, no handler is on the root logger, so Python printed that record and its traceback on stderr after the one-line error. Now a command that reports its own failure is counted one time, its span records its real exit code, and_delegatelogs no record for the exit.docs/TELEMETRY.mddescribes this.The knowledge base pages
configuration_and_settings.mdandlibraries/pyyaml_jinja2.mddescribe the error. The YAML example of the second page raises an error that quotes no text of the file.The config paths that do not load the settings and can still show text of a config file are #2451. One exit seam that reports a
DevOpsCLIErrorwith no traceback for every command is #1006.Closes #1468
Change:
openspec/changes/archive/2026-10-28-1468-config-parse-error-hides-line/