Repository navigation
Validate the configuration with zod - #35
Merged
Merged
Conversation
The merged configuration is validated when a Logger is created, after env() placeholders are resolved. All problems are reported at once with their path, unknown options are rejected. Plugins hook into the validation with a static `configSchema`: the logger loads the configured plugins first and validates their options together with its own. The Sentry plugin defines its options this way and accepts strings for booleans and numbers, so they can be set with env(). BREAKING CHANGE: Unknown options and invalid values throw an error. Only the standard log levels are allowed. Plugins that read their own options from the configuration need to provide a `configSchema`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
Moved into #34 (it shows as merged because the commit is now part of that branch). |
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.
Summary
Builds on #34. Misconfigurations now fail when the first
Loggeris created instead of silently misbehaving.env()placeholders are resolved. All problems are reported at once with their path; unknown options are rejectedconfigSchema. The logger loads the configured plugins first, merges their schemas into its strict schema and validates everything together. A plugin redefining a core option (or another plugin's option) is rejectedsentryConfigSchema), booleans and numbers accept strings so they can be set withenv(), andexceptionLevelmust be one of the configured levelsConfigstays an interface, so plugins can still augment itPreviously silent problems that are caught now, e.g.:
"plugins": "…"as string crashed withconfig.plugins.map is not a function"sentry": { "exceptionLevel": "fatal" }never sent any exception to Sentry"sentry": { "debug": "env(SENTRY_DEBUG, false)" }enabled debug mode, because"false"is truthyBreaking changes
configSchema, otherwise their options are rejected as unknownTest plan
npm ci,npm run typecheck,npm run lint,npm test(98 tests),npm run buildexamples/test-moduleruns with a valid configuration and fails at startup with the errors above for a broken one, also when the invalid value comes fromenv()🤖 Generated with Claude Code