Skip to content

An empty config file is not a syntax error - #32

Merged
naturalmoods merged 1 commit into
mainfrom
empty-config
Aug 18, 2026
Merged

naturalmoods merged 1 commit into
mainfrom
empty-config

Conversation

@naturalmoods

Copy link
Copy Markdown
Owner

aipocket config path tells you where the config goes. Create that file, paste the example's comment header into it — or leave it empty — and the tool refused to run:

aipocket: ~/.config/aipocket/config.yaml: somewhere in the file: syntax error (the
text at fault is not reproduced here: no redactor exists yet at config-load time,
and a mis-pasted credential is the likeliest thing to be wrong)

Exit code 2, on the first thing a new user does, with a message implying they had pasted a credential somewhere. All three of these produced it:

file contents before after
empty (0 bytes) exit 2, "syntax error" runs
one newline exit 2, "syntax error" runs
only comments exit 2, "syntax error" runs

yaml.v3 signals "no document here" with io.EOF. A missing config was always fine — the tool is usable with environment variables alone, which is the documented first try — so this is the same case one byte later.

The guard is deliberately narrow

Only io.EOF. A malformed document still fails with its line number:

$ AIPOCKET_CONFIG=/tmp/bad.yaml aipocket providers
aipocket: /tmp/bad.yaml: line 3: value has the wrong type for this field …

Swallowing a real syntax error here would be worse than the bug being fixed: the config is where a typo silently withdraws a provider you believed you had disabled, which is why ValidateAgainst and KnownFields(true) exist. The existing parse-error tests hold that in place.

The new test covers all four spellings of "says nothing" (empty, newline, comments, providers: {}) and was watched failing on the first three.

Found by running aipocket providers against /dev/null while checking something else.

🤖 Generated with Claude Code

`aipocket config path` tells you where the config goes. Create that file, paste the
example's comment header into it — or nothing at all — and the tool refused to run:

    aipocket: ~/.config/aipocket/config.yaml: somewhere in the file: syntax error
    (the text at fault is not reproduced here: no redactor exists yet at
    config-load time, and a mis-pasted credential is the likeliest thing to be
    wrong)

Exit code 2, on the first thing a new user does, with a message implying they had
pasted a credential somewhere. yaml.v3 signals "no document here" with io.EOF, and
an empty file, a file holding one newline, and a file holding only comments all
produce it.

A missing config was always fine — the tool is usable with environment variables
alone, which is the documented first try. This is the same case one byte later, so
it is treated the same way.

The guard is narrow on purpose: only io.EOF. A malformed document still fails with
its line number, which the existing parse-error tests hold in place — swallowing a
real syntax error here would be worse than the bug being fixed, because the config
is where a typo silently withdraws a provider you thought you had disabled.

Found by running `aipocket providers` against /dev/null while checking something
else.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@naturalmoods
naturalmoods merged commit 58cd584 into main Aug 18, 2026
5 checks passed
@naturalmoods
naturalmoods deleted the empty-config branch August 18, 2026 17:46
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.

1 participant