Skip to content

Conversation

imhayatunnabi
Copy link

Summary

Problem

When exceptions are wrapped with previous exceptions using the $previous parameter, the error page only shows the top-level exception. This makes debugging difficult as developers cannot see the full exception chain without diving into code, turning a simple one-minute debug into an hour-long investigation.

As requested in #57366:

"When the exception is rendered by Laravel as a response, there is no way to know the previous exception or track the previous exceptions from there."

Solution

1. Exception Chain Traversal (Exception.php:277-301)

Added two new methods to the Exception class:

  • previousExceptions() - Traverses the entire exception chain using $exception->getPrevious() until it returns null, collecting class, message, and code for each
  • hasPreviousExceptions() - Checks if any previous exceptions exist

2. New UI Component (previous-exceptions.blade.php)

Created a new Blade component that displays all previous exceptions in a section styled like the Exception Trace:

3. Template Integration

  • Updated show.blade.php to include the previous exceptions section between trace and queries
  • Updated markdown.blade.php to include previous exceptions in markdown exports for sharing/documentation

4. Test Coverage

Added testItCanRenderPreviousExceptions() that verifies:

  • A chain of 3 nested exceptions is properly rendered
  • All exception messages appear in the output
  • The "Previous exceptions" section header is displayed

Test Plan

  • Added test for rendering exception chains with 3 nested exceptions
  • All existing renderer tests pass (8/8 tests)
  • Verified traversal works until getPrevious() returns null
  • Confirmed UI matches Exception Trace styling
  • Verified previous exceptions included in markdown export

What This Fixes

Resolves #57366 - Exceptions rendering do not expose previous exceptions

@imhayatunnabi imhayatunnabi deleted the feat/display-previous-exceptions branch October 13, 2025 12:20
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.

Exception render does not expose previous exceptions

1 participant