From 46b059dafb38c668468c8b63519039fda6029f9f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Tue, 24 Dec 2024 22:25:50 +0300 Subject: [PATCH 1/2] Improve GitHub CI (#135) --- .github/workflows/bc.yml | 24 +++++++++++++++++-- .github/workflows/build.yml | 5 +++- .../workflows/composer-require-checker.yml | 3 ++- .github/workflows/mutation.yml | 1 + 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.github/workflows/bc.yml b/.github/workflows/bc.yml index 9127600..f8cc564 100644 --- a/.github/workflows/bc.yml +++ b/.github/workflows/bc.yml @@ -1,8 +1,28 @@ on: - - pull_request - - push + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' + push: + branches: ['master'] + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'phpunit.xml.dist' + - 'psalm.xml' name: backwards compatibility + jobs: roave_bc_check: uses: yiisoft/actions/.github/workflows/bc.yml@master diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ed9a60b..e96052e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -24,8 +25,10 @@ name: build jobs: phpunit: uses: yiisoft/actions/.github/workflows/phpunit.yml@master + secrets: + codecovToken: ${{ secrets.CODECOV_TOKEN }} with: os: >- ['ubuntu-latest', 'windows-latest'] php: >- - ['8.0', '8.1', '8.2'] + ['8.0', '8.1', '8.2', '8.3'] diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 6cf3cef..5473ec9 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -11,6 +11,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' @@ -30,4 +31,4 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2'] + ['8.0', '8.1', '8.2', '8.3'] diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index c1aca98..92e4f8d 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -9,6 +9,7 @@ on: - 'psalm.xml' push: + branches: ['master'] paths-ignore: - 'docs/**' - 'README.md' From 16a53fdfb5dd1989cf5d8ca8fa92eee45b3385bb Mon Sep 17 00:00:00 2001 From: Dmitriy Derepko Date: Tue, 24 Dec 2024 21:35:26 +0200 Subject: [PATCH 2/2] Add error code & show function arguments (#125) Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 3 ++- src/ErrorHandler.php | 3 ++- src/Renderer/HtmlRenderer.php | 36 +++++++++++++++++++++++------------ templates/development.php | 1 + 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d03717..aa2d639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # Yii Error Handler Change Log -## 3.3.1 under development +## 3.4.0 under development +- Enh #125: Add error code & show function arguments (@xepozz) - Enh #130: Pass exception message instead of rendered exception to logger in `ErrorHandler` (@olegbaturin) - Enh #133: Extract response generator from `ErrorCatcher` middleware into separate `ThrowableResponseFactory` class (@olegbaturin) diff --git a/src/ErrorHandler.php b/src/ErrorHandler.php index bafea8e..fbf159d 100644 --- a/src/ErrorHandler.php +++ b/src/ErrorHandler.php @@ -134,7 +134,8 @@ public function register(): void return true; } - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + $backtrace = debug_backtrace(0); + array_shift($backtrace); throw new ErrorException($message, $severity, $severity, $file, $line, null, $backtrace); }); diff --git a/src/Renderer/HtmlRenderer.php b/src/Renderer/HtmlRenderer.php index d01b87b..f51b561 100644 --- a/src/Renderer/HtmlRenderer.php +++ b/src/Renderer/HtmlRenderer.php @@ -256,22 +256,34 @@ public function renderCallStack(Throwable $t, array $trace = []): string [], ); - $length = count($trace); - for ($i = 0; $i < $length; ++$i) { - $file = !empty($trace[$i]['file']) ? $trace[$i]['file'] : null; - $line = !empty($trace[$i]['line']) ? $trace[$i]['line'] : null; - $class = !empty($trace[$i]['class']) ? $trace[$i]['class'] : null; - $args = !empty($trace[$i]['args']) ? $trace[$i]['args'] : []; + $index = 1; + if ($t instanceof ErrorException) { + $index = 0; + } + + foreach ($trace as $traceItem) { + $file = !empty($traceItem['file']) ? $traceItem['file'] : null; + $line = !empty($traceItem['line']) ? $traceItem['line'] : null; + $class = !empty($traceItem['class']) ? $traceItem['class'] : null; + $args = !empty($traceItem['args']) ? $traceItem['args'] : []; $parameters = []; $function = null; - if (!empty($trace[$i]['function']) && $trace[$i]['function'] !== 'unknown') { - $function = $trace[$i]['function']; - if ($class !== null && !str_contains($function, '{closure}')) { - $parameters = (new \ReflectionMethod($class, $function))->getParameters(); + if (!empty($traceItem['function']) && $traceItem['function'] !== 'unknown') { + $function = $traceItem['function']; + if (!str_contains($function, '{closure}')) { + try { + if ($class !== null && class_exists($class)) { + $parameters = (new \ReflectionMethod($class, $function))->getParameters(); + } elseif (function_exists($function)) { + $parameters = (new \ReflectionFunction($function))->getParameters(); + } + } catch (\ReflectionException) { + // pass + } } } - $index = $i + 2; + $index++; if ($this->isVendorFile($file)) { $vendor[$index] = $this->renderCallStackItem( @@ -588,7 +600,7 @@ private function groupVendorCallStackItems(array $items): array $groupedItems[$groupIndex][$index] = $item; } - /** @psalm-var array> $groupedItems It's need for Psalm <=4.30 only. */ + /** @psalm-var array> $groupedItems It's needed for Psalm <=4.30 only. */ return $groupedItems; } diff --git a/templates/development.php b/templates/development.php index c6a48c2..669dc1e 100644 --- a/templates/development.php +++ b/templates/development.php @@ -73,6 +73,7 @@ + (Code #getCode() ?>)