Skip to content

Improve stack traces in debug output - #792

Merged
giuscris merged 3 commits into
2.xfrom
feature/improved-errors-trace
Nov 22, 2025
Merged

Improve stack traces in debug output#792
giuscris merged 3 commits into
2.xfrom
feature/improved-errors-trace

Conversation

@giuscris

@giuscris giuscris commented Nov 22, 2025

Copy link
Copy Markdown
Member

This pull request improves error debugging and stack trace visualization across both the main application and the panel. The changes focus on consistently capturing and displaying the full stack trace for exceptions, refining trace formatting, and enhancing the robustness of code frame dumping.

Stack trace handling and display:

  • Added a new getTrace method to both formwork/src/Controllers/ErrorsController.php and formwork/src/Panel/Controllers/ErrorsController.php to generate a complete stack trace, including the exception origin, and handle edge cases for Error and ErrorException types. This trace is now passed as stackTrace to error views. [1] [2]
  • Updated error views (formwork/views/errors/partials/debug.php and panel/views/errors/error.php) to iterate over the new stackTrace array, ensuring all relevant frames are displayed and the first frame is expanded by default. [1] [2]

Robustness and formatting improvements:

  • Improved the CodeDumper::dumpBacktraceFrame method to validate frame structure, handle missing keys gracefully, and avoid errors when dumping code for incomplete frames.
  • Refined argument handling in CodeDumper::dumpBacktraceFrame to prevent undefined index errors and ensure correct parameter display. [1] [2]
  • Adjusted trace call margin styling in CodeDumper for a more compact and readable display.

@giuscris giuscris added this to the 2.2.0 milestone Nov 22, 2025
@giuscris
giuscris requested a review from Copilot November 22, 2025 11:52
@giuscris giuscris self-assigned this Nov 22, 2025
@giuscris giuscris added the enhancement New feature or request label Nov 22, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves stack traces in debug output by including the exception origin point in the trace and making the display more comprehensive. The key changes refactor how stack traces are generated and displayed in error views.

  • Introduces a new getTrace() method that constructs a complete stack trace including the exception's origin point
  • Updates error views to use the new stackTrace variable instead of calling getTrace() directly on the throwable
  • Modifies CodeDumper::dumpBacktraceFrame() to handle frames without function information (e.g., the exception origin)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
formwork/src/Panel/Controllers/ErrorsController.php Adds getTrace() method to build complete stack trace with exception origin; passes stackTrace to views
formwork/src/Controllers/ErrorsController.php Adds getTrace() method identical to Panel version for consistency across error controllers
panel/views/errors/error.php Updates to use stackTrace variable; opens first frame by default; checks for both throwable and stackTrace
formwork/views/errors/partials/debug.php Updates to use stackTrace variable; opens first frame by default
formwork/src/Debug/CodeDumper.php Updates dumpBacktraceFrame() to handle frames without function info; adds validation and null-safe access to optional frame properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread formwork/src/Panel/Controllers/ErrorsController.php
Comment thread formwork/src/Controllers/ErrorsController.php
Comment thread formwork/src/Panel/Controllers/ErrorsController.php Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@giuscris
giuscris merged commit 6dff6d5 into 2.x Nov 22, 2025
1 check passed
@giuscris
giuscris deleted the feature/improved-errors-trace branch November 22, 2025 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants