fix(#45): graceful config validation on the standalone boot path#59
Merged
Conversation
Values the CLI's parse layer tolerates for PostgREST --dump-config parity
(e.g. db-max-rows=0, server-port=0 or negative) crashed boot with a raw
MatchError/ArgumentError because they only hit Bier's NimbleOptions schema
inside Bier.start_link/1.
- Add Bier.Config.new/2, the non-raising variant of new!/2 (which now
delegates to it), returning {:ok, config} | {:error, message} for both
schema and semantic validator failures.
- Add Bier.CLI.Config.validated_start_opts/1: to_start_opts/1 plus a full
Bier.Config.new/2 pass, with multi-line NimbleOptions messages collapsed
to the CLI's one-line fatal format.
- Route both boot paths through it: the escript boot in Bier.CLI.main/1
emits the message on stderr and exits 1 (like the jwt-secret/admin-port
fatals); Bier.Application.standalone_spec/1 returns the fatal message.
- --dump-config is untouched: validation runs at boot, not at parse/dump,
so the conformance-pinned dump behavior is preserved (pinned by new
tests in test/bier/cli/boot_validation_test.exs).
Part of #45.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Values the CLI's parse layer accepts for PostgREST
--dump-configparity — e.g.db-max-rows=0,server-port=0or negative (Bier's schema uses:pos_integer, i.e. >= 1) — passed--dump-configbut crashed boot with a rawMatchError/ArgumentErrorfrom insideBier.start_link/1.docker runfirst-contact users hit exactly this. This is the open hardening tail from the #40 review noted on #45.How
Bier.Config.new/2: non-raising variant ofnew!/2(which now delegates to it), returning{:ok, config} | {:error, message}for both NimbleOptions schema failures and the semantic validators (jwt-secret / jwt-aud / db-channel / admin-port). Validator failures still raiseArgumentErrorfromnew!/2as before; schema failures now raiseArgumentErrortoo (previouslyNimbleOptions.ValidationError— nothing depended on that type).Bier.CLI.Config.validated_start_opts/1:to_start_opts/1plus a fullBier.Config.new/2pass, collapsing multi-line NimbleOptions union-type messages into the CLI's one-line fatal format.Bier.CLI.main/1prints the message to stderr and exits 1 (same shape as the existing jwt-secret/admin-port fatals), andBier.Application.standalone_spec/1(theBIER_STANDALONErelease/Docker path) returns the fatal message thatstandalone_children/1already reports on stderr before halting.--dump-configparity preserved: validation runs at BOOT, not at parse/dump — the dump still prints whatever was parsed (e.g.db-max-rows = 0,server-port = -1) and exits 0, exactly as the conformance cases pin it.Out of scope (still open on #45):
--readysubcommand, db-config source, Docker smoke CI job.Part of #45.
Verification
mix format --check-formatted,mix compile --warnings-as-errors,MIX_ENV=test mix compile --warnings-as-errors,mix credo --strict,mix docs --warnings-as-errors,mix deps.unlock --check-unused— all clean locally.mix run --no-start):db-max-rows=0/server-port=0/server-port=-1now yield single-line{:error, message}; valid config yields the same opts asto_start_opts/1;--dump-configwith those values still exits 0.test/bier/cli/boot_validation_test.exscover the error paths, the standalone spec,Bier.Config.new/2, and the dump parity; CI runs them (conformance suite is the judge, per repo policy).🤖 Generated with Claude Code