Skip to content

Show step errors on GET requests instead of a fatal error - #174

Merged
sorinmarta merged 3 commits into
masterfrom
fix-3210
Oct 29, 2026
Merged

sorinmarta merged 3 commits into
masterfrom
fix-3210

Conversation

@sorinmarta

Copy link
Copy Markdown
Contributor

Fixes Strategy11/awpcp#3210
Pass the original errors array to AWPCP_Exception again so GET step errors render the "cannot be processed" message and the errors instead of a TypeError.

@sorinmarta sorinmarta added run analysis Run the phpcs run tests Run the unit tests franky-review labels Oct 29, 2026
Both functions have been no-ops since PHP 8.0 and are deprecated in
PHP 8.5, which fails the PHPCS inspection.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 33 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9399352d-fb30-42ad-9c89-ce2b08cb3b66
Commits

Reviewing files that changed from the base of the PR and between bfe8761 and f23c09f.

Files selected for processing: 1
  • includes/views/class-base-page.php

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 42833ea5-c283-4ac5-9361-3eeaf3181122
Commits

Reviewing files that changed from the base of the PR and between 357533e and bfe8761.

Files selected for processing: 3
  • includes/functions/deprecated.php
  • includes/media/class-mime-types.php
  • includes/views/class-base-page.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The changes replace explicit image and fileinfo resource release calls with unset(). Exception handling continues to escape the message but passes the error list without applying esc_html().

Changes

Exception error handling

Layer / File(s) Summary
Exception construction
includes/views/class-base-page.php
The replacement exception receives the escaped message and the original error list.

Resource cleanup

Layer / File(s) Summary
Image and fileinfo cleanup
includes/functions/deprecated.php, includes/media/class-mime-types.php
The resizer unsets its source and temporary image variables. MIME detection unsets the fileinfo resource.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: stephywells, wvega

Merge Risk: Minimal · previous review bfe87

No merge-blocking risk was established in the exception handling or resource cleanup changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: GET step errors now display instead of causing a fatal error.
Description check Passed The description directly explains the error handling change and references the related issue.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Oct 29, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approve (non-blocking notes below).

Verified live (WordPress Playground, PHP 8.5, harness mu-plugin driving a real AWPCP_BasePage subclass whose step throws AWPCP_Exception):

  • Base 357533e5, GET request: handle_step_exception() fatals with TypeError: Exception::__construct(): Argument #2 ($code) must be of type int, string given (esc_html() turns the errors array into the string "Array"). PR bfe87612: the page renders the generic "Your request cannot be processed…" notice plus the original message and the extra errors.
  • Output safety: with <script> and a javascript: link in the exception message, the rendered page has both stripped (awpcp_print_error() runs wp_kses_post), so dropping esc_html() on the errors array does not open an XSS hole. POST path is identical on base and PR.
  • unset() swaps: AWPCP_MimeTypes fileinfo path still returns image/png / image/jpeg, and awpcp_resizer() still shrinks PNG and JPEG to 640x480. Base prints PHP 8.5 Deprecated notices for finfo_close() and imagedestroy(), PR prints none. Unset frees the resource on 7.4 too, and the PHP 7.4 and PHP 8 CI jobs pass.
  • Repo-wide grep for the same esc_html( <array> ) shape: none left. Remaining finfo_close/imagedestroy references: only the function_exists check below.

Non-blocking

  1. includes/media/class-mime-types.php:19 still requires function_exists( 'finfo_close' ) to use fileinfo. PHP 9 will remove that function, so the fileinfo path would then be skipped silently in favour of the array fallback. Since the PR stops calling finfo_close(), drop it from the condition.
  2. No regression test for the GET-error path (a step that throws on GET should render errors, not fatal). Not blocking for a one-line fix, but this is the kind of path that regresses unseen.
  3. The finfo_close/imagedestroy → unset() commit is unrelated to the PR title and the linked fix; fine to keep, but worth naming in the description.

Not run: the real front-end Place Ad / Buy Credits flows (only the base-page error handler was exercised directly), PHPUnit locally (CI green).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Oct 29, 2026
@sorinmarta
sorinmarta merged commit 4076294 into master Oct 29, 2026
5 checks passed
@sorinmarta
sorinmarta deleted the fix-3210 branch October 29, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Run the phpcs run tests Run the unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant