Skip to content

Site Health: Avoid shell error output when Ghostscript is missing. - #14009

Open
accolette wants to merge 1 commit into
WordPress:trunkfrom
accolette:66245-fix-ghostscript-warning
Open

accolette wants to merge 1 commit into
WordPress:trunkfrom
accolette:66245-fix-ghostscript-warning

Conversation

@accolette

Copy link
Copy Markdown

When Ghostscript (gs) is not installed, WP_Debug_Data::get_wp_media() runs gs --version through exec(). exec() only captures stdout, so the shell prints an error on stderr (for example sh: 1: gs: not found, the exact wording depends on the shell). It is visible in the terminal, in WP-CLI and in PHPUnit output.

The "Ghostscript version" field is already correctly reported as "Not available", so this change only removes the unwanted shell output. The reported result does not change.

Changes

  • Check that gs exists with command -v before running gs --version.
  • Add tests/phpunit/tests/admin/wpDebugData.php with two tests on the Ghostscript field returned by WP_Debug_Data::debug_data():
    • gs is available (a fake gs script is added to the PATH): the version is reported.
    • gs is missing (the PATH does not contain it): the field is reported as "not available".

Testing

Run:

npm run test:php -- --filter Tests_Admin_wpDebugData

  • Without the fix: the 2 tests pass, and sh: 1: gs: not found is printed in the output.
  • With the fix: the 2 tests pass, and nothing is printed.

The tests cannot assert on the message itself, because it is written to stderr by the child process and not by PHP. They check that the reported value is unchanged, and the message is checked by looking at the output. WP-CLI steps to reproduce are in the ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/66245

Use of AI Tools

AI assistance: Yes. Tool(s): Claude (Anthropic). Used for: helping me understand the problem, looking up the affected version, suggesting reproduction commands, and drafting the PHPUnit tests, the Trac ticket text and this description. I found the bug, reproduced it, ran the tests and tested the patch.

The fix was suggested by Chouby.

`WP_Debug_Data::get_wp_media()` ran `gs --version` without checking that `gs` exists. When it is not installed, the shell prints an error on stderr (visible in the terminal, WP-CLI and PHPUnit output) even though the "Not available" case is already handled.

Check that `gs` exists with `command -v` before running it. Add tests covering both cases: `gs` available and missing.

See #66245.
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @accolette.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant