Skip to content

fix(config): a config file that is not valid YAML stops the load with an error that quotes none of its text - #2468

Merged
dan-petty merged 13 commits into
mainfrom
fix/1468-config-parse-error-hides-line
Oct 28, 2026
Merged

dan-petty merged 13 commits into
mainfrom
fix/1468-config-parse-error-hides-line

Conversation

@dan-petty

@dan-petty dan-petty commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

load_settings reads the global config file and the project config file through one helper, _read_config_file in src/devops_cli/config/settings.py. When a file is not valid YAML, the helper raises ConfigurationError with the message Cannot load the settings: <file> is not valid YAML (<error type>) at line <n>, column <n>. The line and the column come from the problem_mark of the PyYAML error. The message quotes no text of the file.

Before this change, each command that loads the settings let the yaml.YAMLError go 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 for devops config audit-keys only.

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 raises ValueError, KeyError, IndexError or AttributeError for a tagged value that it cannot build, such as !!int <text>, and the message of that error can quote the value. It raises RecursionError for a document that nests too deep. A file that is not UTF-8 raises UnicodeDecodeError, 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 catch Exception, because the swallowed-failures ratchet refuses a new blind except in src/. An OSError names only the file, so it goes up as before.

The helper raises the error after its except block, so the error has no __cause__ and no __context__. The Mark of a PyYAML error holds the full text of the file in its buffer, and raise ... from None only hides __context__ from the traceback. Thus no traceback or log record holds the PyYAML error.

devops config get loads the settings inside exit_on_error(ConfigurationError), as devops config unset does. It prints the error on one line, prints no traceback, and exits 1.

main._delegate raises the exit of a command that returns a non-zero exit code in the else clause of its try. Before, it raised that exit inside the try, and its own except Exception caught it, because typer.Exit is a RuntimeError. That clause counted the command a second time in devops_cli_command_total, set cli.exit_code to 1, and logged Command '<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 _delegate logs no record for the exit. docs/TELEMETRY.md describes this.

The knowledge base pages configuration_and_settings.md and libraries/pyyaml_jinja2.md describe 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 DevOpsCLIError with no traceback for every command is #1006.

Closes #1468

Change: openspec/changes/archive/2026-10-28-1468-config-parse-error-hides-line/

@dan-petty dan-petty added scope/config Settings, OS Keyring, environment variables, and defaults scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger type/security Type security: a vulnerability or a leak labels Oct 28, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test results

Targeted tests on the branch after the rebase onto origin/main (8b650a6):

uv run devops ci test tests/config/test_config_file_that_is_not_yaml.py tests/config/test_config_key_removal.py tests/config/test_unknown_config_keys.py tests/config/test_config_keys.py tests/commands/test_config.py tests/test_config_env_overrides.py tests/test_otel_command_coverage.py
94 passed in 7.05s

Before the second rebase, uv run devops ci test with these test files and the changed sources (src/devops_cli/config/settings.py, src/devops_cli/main.py, src/devops_cli/commands/config.py, src/devops_cli/docs/generator.py) ran the mapped tests: 4909 passed.

uv run devops openspec archive 1468-config-parse-error-hides-line: every spec and change validates.

Fail-to-pass

uv run devops ci fail-to-pass --base origin/main exited 0. 4 tests fail on the base tree and 16 pass. The fail-to-pass check run of this pull request replays the tests on the base again.

  failed on base: tests.config.test_config_file_that_is_not_yaml::test_a_config_file_that_is_not_yaml_names_its_file_line_and_column_and_quotes_no_text (yaml.scanner.ScannerError: mapping values are not allowed here)
  failed on base: tests.commands.test_config::test_config_unset_removes_a_key_that_stops_every_command_from_loading_the_settings (assert (1, '') == (1, '✗ Unknow...i.vllm_url\n'))
  passed on base: tests.commands.test_config::test_config_unset_dry_run_prints_the_change_and_writes_nothing
  passed on base: tests.commands.test_config::test_config_unset_of_a_key_that_the_file_does_not_hold_exits_1_and_changes_nothing
  failed on base: tests.commands.test_config::test_config_get_reports_a_config_file_that_is_not_yaml_on_one_line_with_no_file_text (AssertionError: assert (1, <class 'y...erError'>, '') == (1, <class 'S...column 22.\n'))
  passed on base: tests.commands.test_config::test_config_init_names_the_active_config_file_it_writes
  passed on base: tests.commands.test_config::test_the_unset_command_that_the_error_names_for_the_other_config_file_removes_the_key
  passed on base: tests.test_config_env_overrides::test_ai_config_for_task_with_context_window_overrides
  passed on base: tests.test_config_env_overrides::test_telemetry_invalid_variables_fail_load_settings_but_keep_export_off[DEVOPS_CLI_TELEMETRY_ENABLED-bogus]
  passed on base: tests.test_config_env_overrides::test_the_registered_telemetry_variables_reach_the_settings_and_the_tracer
  passed on base: tests.test_config_env_overrides::test_the_environment_pins_review_analysis_to_one_model
  passed on base: tests.test_config_env_overrides::test_unregistered_telemetry_variables_configure_nothing
  passed on base: tests.test_config_env_overrides::test_the_otel_standard_endpoint_is_only_the_fallback
  passed on base: tests.test_config_env_overrides::test_ai_gateway_url_environment_variable_override_and_spec
  passed on base: tests.test_config_env_overrides::test_load_settings_applies_embedding_task_and_rag_url_overrides
  failed on base: tests.test_config_env_overrides::test_the_telemetry_variables_hold_when_the_settings_cannot_load[malformed-configuration] (yaml.parser.ParserError: while parsing a flow node)
  passed on base: tests.test_config_env_overrides::test_the_telemetry_variables_hold_when_the_settings_cannot_load[unrelated-variable-cannot-apply]
  passed on base: tests.test_config_env_overrides::test_load_settings_applies_env_overrides_for_non_secret_fields
  passed on base: tests.test_config_env_overrides::test_telemetry_invalid_variables_fail_load_settings_but_keep_export_off[DEVOPS_CLI_TELEMETRY_ENDPOINT-localhost:4318]
  passed on base: tests.test_config_env_overrides::test_find_project_config_path_skips_directory
4 failed on base (4 failed and 16 passed in tests/commands/test_config.py, tests/config/test_config_file_that_is_not_yaml.py, tests/test_config_env_overrides.py; 0 errored).
Elapsed: 14s

@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 17:28
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.
…settings

The audit record of a config write, the round-trip of config set and config unset, and the KeyError of !!bool <text> in config audit-keys can still show text of a config file. They do not load the settings, so #1468 does not cover them. #2451 owns them.
@dan-petty
dan-petty force-pushed the fix/1468-config-parse-error-hides-line branch from 4d518fc to 907ae10 Compare October 28, 2026 17:37
@dan-petty

Copy link
Copy Markdown
Owner Author

Fix round 1: Tests & Coverage

The Tests & Coverage job of run 40735411127 failed on one test: tests/test_swallowed_failures_ratchet.py::test_swallowed_failures_stay_under_or_equal_to_ceiling. The except Exception in _read_config_file was a sixth BLE001 site in src/devops_cli/config/settings.py, and the ceiling of that file is 5.

The fix keeps the ceiling. _read_config_file now catches (yaml.YAMLError, ValueError, LookupError, AttributeError, RecursionError) by name. A run of yaml.safe_load (PyYAML 6.0.3) on each kind of bad value gave the list: !!int '' raises IndexError, and a document that nests 3000 levels raises RecursionError. The new test cases empty-int and deep-nesting fail when their type is not on the list.

The branch is rebased onto origin/main (960e357), and the change is archived again in the last commit.

Targeted tests:

uv run devops ci test tests/config/test_config_file_that_is_not_yaml.py tests/test_swallowed_failures_ratchet.py tests/commands/test_config.py tests/test_config_env_overrides.py tests/test_otel_command_coverage.py tests/config/test_config_keys.py tests/config/test_config_key_removal.py tests/config/test_unknown_config_keys.py tests/test_change_folders.py
121 passed in 12.60s

uv run devops ci test tests/invariants/test_*.py tests/test_kb.py tests/test_kb_manuals_metadata.py
42 passed in 13.75s

uv run devops docs check and uv run devops openspec check pass.

@dan-petty
dan-petty merged commit 91fe5dc into main Oct 28, 2026
18 of 20 checks passed
@dan-petty
dan-petty deleted the fix/1468-config-parse-error-hides-line branch October 28, 2026 17:50
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/config Settings, OS Keyring, environment variables, and defaults scope/security Security linters (trivy, bandit, gitleaks, kubeconform) and Vault scope/telemetry OpenTelemetry tracing spans, Prometheus metrics, and Jaeger type/security Type security: a vulnerability or a leak

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(config): a config file that does not parse never prints its line from any command that loads settings

1 participant