Preserve $previous chain in exception wraps#35
Merged
Conversation
Five wrap sites (4 in CliLoginHelper, 1 in OpenIdLoginAuthenticator::validateClaims) copied the message from the caught exception but discarded the chain. Logs lost the originating PSR cache / upstream OIDC failure, making debug traversal impossible. Add `previous: $e` to each `new CacheException(...)` / `new ValidationException(...)`. Test changes: convert the existing message-only assertions to a try/catch + early-return pattern so each test also asserts `getPrevious()` returns the original cause object. Five existing tests touched; test count and coverage unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #35 +/- ##
===========================================
Coverage 100.00% 100.00%
Complexity 60 60
===========================================
Files 9 9
Lines 278 278
===========================================
Hits 278 278
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
turegjorup
added a commit
that referenced
this pull request
May 11, 2026
Records the decision to migrate the bundle (and upstream library) to a marker-interface exception contract: cross-package marker interfaces, concretes extending SPL types, wrap-at-boundary discipline with `$previous` chained, and the controller HTTP-exception exit treated as a documented carve-out. Migration via coordinated 5.0 majors across `itk-dev/openid-connect` and this bundle, sequenced as four PRs. PR 0 (cause-chain bug fixes) already in flight as PR #35. The ADR is self-contained: context, drivers, three options considered, decision, consequences, and references (PSR-18, Symfony's component markers and Psr18Client, Bloch's wrap-at-boundary principle). Status: Draft — awaits team review. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jekuaitk
approved these changes
May 11, 2026
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
Five sites in the bundle catch an upstream exception and rethrow as a bundle exception with the message copied — but the chain to the originating exception is dropped. This means error logs (and
$e->getPrevious()traversal) lose the underlying PSR cache or upstream OIDC failure, making debug from a 500/503 response impossible to root-cause without reading the bundle source.Fixed by adding
previous: $e(named argument) to eachnew CacheException(...)/new ValidationException(...). No public API change; concrete exception types and messages are unchanged.Sites fixed
src/Util/CliLoginHelper.phpcreateTokenfirstgetItemInvalidArgumentExceptionCacheExceptionsrc/Util/CliLoginHelper.phpcreateTokensecondgetItemInvalidArgumentExceptionCacheExceptionsrc/Util/CliLoginHelper.phpgetUsernamegetItemInvalidArgumentExceptionCacheExceptionsrc/Util/CliLoginHelper.phpgetUsernamedeleteItemInvalidArgumentExceptionCacheExceptionsrc/Security/OpenIdLoginAuthenticator.phpvalidateClaimstoken validationItkOpenIdConnectExceptionValidationExceptionTests
Converted the five existing
expectException+expectExceptionMessagetests to atry/catch/early-return pattern so each test now also assertsgetPrevious()returns the original cause object (same pattern as PR #33). Test count (56) and coverage (100%) unchanged.Backward compatibility
Additive only. Consumers reading
$e->getMessage()or catching the concrete exception types still behave the same. Consumers reading$e->getPrevious()now get the cause they previously gotnullfor — a strict improvement.Test plan
task test— 56 tests, 141 assertions passtask analyze:php— phpstan max, no errorstask lint:php— cleantask test:matrix— pending in CIContext
Part of the larger exception-contract migration described in
EXCEPTION-CONTRACT-MIGRATION.md(PR 0). Self-contained patch-level fix; does not depend on the upcoming 5.0 contract work.🤖 Generated with Claude Code