Repository navigation
Report configuration errors instead of printing them - #74
Merged
Merged
Conversation
- Collect environment parse failures during initialisation. - Fail startup when any were recorded.
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.
Behaviour change: a deployment with a malformed setting that starts today will refuse to start after this.
Five
initfunctions parsed environment settings, printed any failure withfmt.Printf, and carried on with a partly populated struct:Two problems followed.
A misconfigured deployment started anyway, on silent defaults. That matters most for
DIMS_ALLOWED_SOURCE_BACKENDS, where the default is the narrow value and a typo would quietly widen or narrow what the service will fetch.And these run before
slogis configured inRun, so the messages bypassedDIMS_LOG_FORMAT=jsonentirely and arrived as bare stdout lines no log pipeline would parse. The one thing an operator needs to see was the one thing they could not search for.The change
Failures are collected during initialisation and reported by
Config.Validate, whichservealready calls after logging is set up.errors.Joinkeeps all of them rather than only the first.The five call sites move from
fmt.PrintftoRecordStartupError.encryption.goalso stops usingslog.Errorfor its key derivation failure, for the same reason: nothing is listening yet.This deliberately avoids restructuring initialisation. Moving configuration loading out of
initwould change package initialisation order and when source backends register, which is a larger change than the problem needs.Effect
Previously that printed a similar line and started the server on defaults.
Tests
internal/core/config_test.gocovers a recorded error surfacing throughValidate, a clean configuration passing, an unknownDIMS_DEFAULT_OUTPUT_FORMATbeing refused, andRecordStartupErrorignoring nil. Each saves and restores the package state so ordering does not matter.Verification
In
ghcr.io/beetlebugorg/go-dims:builder:gofmt,go vet, andgo test -race ./...all pass. The failure above is from the built binary.