Skip to content

fix(config): refuse a malformed chartula.yaml naming the file, line and column - #238

Merged
goldbarth merged 1 commit into
mainfrom
fix/malformed-chartula-yaml
Sep 23, 2026
Merged

goldbarth merged 1 commit into
mainfrom
fix/malformed-chartula-yaml

Conversation

@goldbarth

Copy link
Copy Markdown
Owner

Closes #237

  • Read with positions, not deserialized to object: ChartulaYamlReader loads the file through YamlDotNet's representation model, which keeps the line and column of every key and value (and is reflection-free, so no step back for the AOT goal). The flattening into Chartula: keys is unchanged.
  • Syntax errors become configuration errors: file, line and column, YamlDotNet's reason without its (Line: .., Col: .., Idx: ..) prefix, and what it most likely means:
    • a line indented under a key that already has a value (the case in the issue) is named as such, with both lines and their indentation;
    • a line that lines up with no key above it names the levels that exist;
    • a tab is named on its own line - YamlDotNet reports line 1, column 1 for it;
    • an unclosed [/{ says so; a duplicate key is refused instead of the last one winning silently.
  • Unknown keys are refused, not ignored: binding drops a key it does not know, so faithfulness: indented under llm: - valid YAML once the 4-space lines are fixed - left thorough: false without effect. The refusal says what the key most likely is: a section of its own, a key of another section ('model' is a key of 'llm' and 'faithfulness'), or a misspelling (Did you mean 'model'?). Keys of maps the user names (labels.category, categories.names) are free.
  • Wrong shapes and types: true/false keys take only those (the binder's message named Chartula:Faithfulness:Thorough and System.Boolean, and no line); list keys take a list, other keys a single value; a section takes keys. Values beyond that (thinking, depth, maxOutputTokens) are still checked where they are read, as before.
  • Schema by hand, held to the types: ChartulaYamlSchema lists every key; ChartulaYamlSchemaTests fails when an options type gains a property the list does not have, or the reverse.
  • Unchanged: an empty value, ~ or null still leaves the setting unset; keys are still case-insensitive; the environment-only refusal still comes first and reads as before. Every problem is named at once, one per line.
  • Docs: configuration.md (A file that cannot be read as meant), cli.md (Configuration file).

Reproduced before the fix with the release binary, the file from the issue:

Unhandled exception. (Line: 3, Col: 10, Idx: 36) - (Line: 3, Col: 10, Idx: 36): YamlDotNet.Core.SemanticErrorException: While scanning a plain scalar value, found invalid mapping.
   at YamlDotNet.Core.Parser.ParseNode(Boolean isBlock, Boolean isIndentlessSequence, Boolean isKey)
   ...
[exit code: 134]

Tabs and an unclosed [ crashed the same way; an unknown key, faithfulness: under llm:, a scalar for a list, a list for a scalar and a duplicate key ran with the setting silently not in force.

Verified after the fix, same file, exit code 1:

Configuration error: chartula.yaml, line 3, column 10: this is not valid YAML (While scanning a plain scalar value, found invalid mapping). Check the indentation: line 3 is indented further than line 2 (4 spaces against 2), but line 2 already has a value, so nothing can be nested under it. The keys of one section line up.

The other cases, each exit code 1:

chartula.yaml, line 4, column 3: this is not valid YAML (While parsing a block mapping, did not find expected key). Check the indentation: line 4 is indented 2 spaces, which lines up with no key above it (they are at 0 or 4). The keys of one section line up.
chartula.yaml, line 2, column 1: this line is indented with a tab. YAML indents with spaces only.
chartula.yaml, line 2, column 1: this is not valid YAML (While parsing a flow sequence, did not find expected ',' or ']'). Check that every '[' and '{' on it is closed.
chartula.yaml, line 4, column 3: 'faithfulness' is not a key of 'llm' but a section of its own. Check the indentation: 'faithfulness:' starts at the beginning of its line, like 'llm:'.
chartula.yaml, line 2, column 3: unknown key 'modle' in 'llm'. Did you mean 'model'?
chartula.yaml, line 1, column 1: unknown key 'model' at the top level: it is a key of 'llm' and 'faithfulness'. Check the indentation: it belongs indented under its section.
chartula.yaml, line 2, column 13: 'faithfulness.thorough' is 'maybe'; expected true or false.
chartula.yaml, line 2, column 22: 'filter.excludeCategories' takes a list, such as [a, b], not the value 'Internal'.
chartula.yaml, line 2, column 10: 'llm.model' takes a single value, not a list.
chartula.yaml, line 3, column 1: 'llm' is set a second time here; the second would replace the first. Set it once.

Tests: MalformedYamlTests (every case above, all problems at once, file named as found, empty values and casing unchanged, the documented example and this repository's chartula.yaml accepted), ChartulaYamlSchemaTests (schema matches the options types), MalformedConfigurationTests (the built CLI on the issue's file: exit 1, no stack trace); full suite 775 passing, build and dotnet format clean. Merged together with #235 and #236: 804 passing.

@goldbarth goldbarth self-assigned this Sep 23, 2026
@goldbarth
goldbarth merged commit aa6ee34 into main Sep 23, 2026
4 checks passed
@goldbarth
goldbarth deleted the fix/malformed-chartula-yaml branch September 23, 2026 14:04
goldbarth added a commit that referenced this pull request Oct 1, 2026
…320)

Follows #319 (ADR 0004); this branch builds on it for the index row and
is rebased onto `main` once #319 is merged.

- **Why:** seven changes since September made Chartula stop where it
used to choose silently, each with its own reasoning in its pull
request, but the rule they share was written down nowhere. A contributor
adding an option or a setting could not tell whether to refuse an
ambiguous value or take the likelier reading, nor when refusing goes too
far.
- **Context** lists the seven cases in one table, each with what the
silent choice did and the change that ended it: a first tag (#198 for
#138, #282), a key sent to the other provider's host (#235), an unknown
or misindented key (#238), a shallow clone read as a first release
(#244), review mode approving unseen text (#247), two configuration
files (#287 for #278), and options a command does not take (#301).
Decided is #198, the first of them.
- **Decision:** stop and say so instead of choosing; before anything is
spent; with a message that names the cause and the fix, shown with two
real messages; ask at a terminal where the answer is the user's, and
stop naming the option without one; refuse only what Chartula can tell
for certain (an empty list, an unknown host and an unknown model id are
taken as written); refuse a setting that would have no effect. The rule
is about what the user meant, not about what the release says, which is
what flags are for.
- **Consequences** name the cost: a run that could have produced
something stops, and a CI job fails until the input says what it means.
The ADR weighs that rerun against what a silent choice cost in the seven
cases. For a new case, four questions in order, so a contributor can
apply the rule rather than match it against the examples.
- The index in `adr/README.md` lists 0005.

**Verified:**
- Each case was checked against its pull request's description and the
issue it closes (#237, #243, #233, #278, #300, #138); the dates are the
merge dates.
- Both messages are the ones `docs/cli.md` and `docs/configuration.md`
show from the built binary.
- The counter-cases were checked in the code: `ProviderHost` accepts
every host but two, `ClaudeThinkingSupport` passes an unknown model id,
#289 reads an empty list as written, and #244 still runs `--since` in a
shallow clone when the range holds.
- Every relative link and anchor in all Markdown files of the repository
resolves (script, with a negative test).

Tests: none, documentation only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A malformed chartula.yaml crashes the run

1 participant