Skip to content

Validate the configuration with zod - #35

Merged
eXaminator merged 1 commit into
update-all-dependenciesfrom
config-validation
Oct 13, 2026
Merged

eXaminator merged 1 commit into
update-all-dependenciesfrom
config-validation

Conversation

@eXaminator

Copy link
Copy Markdown
Member

Summary

Builds on #34. Misconfigurations now fail when the first Logger is created instead of silently misbehaving.

  • Validation with zod 4 – the merged configuration (package.json + Logger options) is validated after env() placeholders are resolved. All problems are reported at once with their path; unknown options are rejected
  • Plugin hook – a plugin class can provide a static configSchema. 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 rejected
  • Sentry plugin – defines its options via the hook (sentryConfigSchema), booleans and numbers accept strings so they can be set with env(), and exceptionLevel must be one of the configured levels
  • Types are derived from the schemas; Config stays an interface, so plugins can still augment it
  • Docs for validation, writing plugins and the Sentry options
Error: Invalid node-logger configuration:
✖ Unrecognized key: "maxlevel"
✖ Invalid input: expected number, received NaN
  → at sentry.maxBreadcrumbs
✖ Invalid option: expected one of "emergency"|"alert"|"critical"|"error"|"warning"|"notice"|"info"|"debug"
  → at sentry.exceptionLevel

Previously silent problems that are caught now, e.g.:

  • "plugins": "…" as string crashed with config.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 truthy

Breaking changes

  • Unknown options and invalid values throw an error
  • Only the eight standard log levels are allowed (custom level names were never covered by the types)
  • Plugins that read their own options from the configuration need to provide a configSchema, otherwise their options are rejected as unknown

Test plan

  • npm ci, npm run typecheck, npm run lint, npm test (98 tests), npm run build
  • Config tests with fixture plugins: plugin options validated and defaulted, unknown plugin options rejected, conflicting plugin options rejected
  • examples/test-module runs with a valid configuration and fails at startup with the errors above for a broken one, also when the invalid value comes from env()

🤖 Generated with Claude Code

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>
@eXaminator
eXaminator merged commit 5a001a2 into update-all-dependencies Oct 13, 2026
1 check passed
@eXaminator
eXaminator deleted the config-validation branch October 13, 2026 14:58
@eXaminator

Copy link
Copy Markdown
Member Author

Moved into #34 (it shows as merged because the commit is now part of that branch).

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