Skip to content

feat(bundle): graceful handling of missing secrets in env var processor#26

Open
deluxetom wants to merge 2 commits into
masterfrom
feat/25-graceful-missing-secrets
Open

feat(bundle): graceful handling of missing secrets in env var processor#26
deluxetom wants to merge 2 commits into
masterfrom
feat/25-graceful-missing-secrets

Conversation

@deluxetom

Copy link
Copy Markdown
Collaborator

Closes #25

Implements the design agreed in #25 (comment), test-first (TDD).

What changed

Default: better error, still exceptional. EnvVarProcessor now catches SecretNotFoundException and rethrows Symfony's EnvNotFoundException with the manager name and secret key in the message and the original exception as previous. As a bonus, Symfony's built-in default: processor now composes: %env(default:fallback_param:secretary:default:KEY)%.

Per-reference opt-in. New secretaryOptional: and secretaryArrayOptional: prefixes log a warning through the injected PSR-3 logger and resolve null when the secret is missing.

Global opt-in. New allow_missing_secrets bundle config (defaults to false) applies the same warning + null behavior to all secretary prefixes.

Logging. The processor takes an optional Psr\Log\LoggerInterface (wired to the logger service with IGNORE_ON_INVALID_REFERENCE, NullLogger fallback), so monolog is not required. psr/log added to the bundle and monorepo composer.json.

Note

Only SecretNotFoundException gets this treatment — network, auth, and other adapter errors still bubble up unchanged.

Tests (written first, watched fail, then implemented)

  • Missing secret → EnvNotFoundException with manager + key + previous
  • secretaryOptional: / secretaryArrayOptional: → warning + null
  • allow_missing_secrets: true → warning + null on standard prefixes
  • No logger wired → still resolves null (NullLogger fallback)
  • Existing secrets resolve normally with both prefixes, no log noise
  • Other exceptions bubble up with both prefixes
  • getProvidedTypes() exposes the new prefixes
  • DI wiring: optional logger reference + allow_missing_secrets flag passed through

vendor/bin/phpunit: 44 tests green across Core/Adapters/Bundle. composer ecs and composer psalm clean.

🤖 Generated with Claude Code

deluxetom and others added 2 commits July 7, 2026 06:00
Missing secrets now throw Symfony's EnvNotFoundException (manager and key
in the message, original SecretNotFoundException as previous) instead of
leaking the raw exception, which also lets the built-in default: processor
compose. Opt in to warning-plus-null resolution per reference with the new
secretaryOptional:/secretaryArrayOptional: prefixes, or globally with the
allow_missing_secrets bundle config. Only SecretNotFoundException is
handled; other adapter errors still bubble up.

Closes #25

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…y/config

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@deluxetom deluxetom marked this pull request as ready for review July 7, 2026 11:16
@deluxetom deluxetom requested a review from cryptiklemur July 7, 2026 11:17
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.

SecretaryBundle: better handling of missing secrets — EnvNotFoundException by default, opt-in optional prefixes + allow_missing_secrets

2 participants