Skip to content

Error handling improvements in phpGetThemeDetails - #1087

Merged
fredrikekelund merged 3 commits into
trunkfrom
f26d/php-get-theme-details-improvements
Mar 18, 2025
Merged

Error handling improvements in phpGetThemeDetails#1087
fredrikekelund merged 3 commits into
trunkfrom
f26d/php-get-theme-details-improvements

Conversation

@fredrikekelund

@fredrikekelund fredrikekelund commented Mar 18, 2025

Copy link
Copy Markdown
Contributor

Related issues

Proposed Changes

  • Stop sending exceptions thrown in phpGetThemeDetails to Sentry. These exceptions indicate more general errors with the PHP-WASM environments and don't tell us anything useful.
  • Parse the PHP output with zod to ensure we conform to the expected schema.

Important

This PR should also fix some of the Sentry issues connected with https://github.com/Automattic/dotcom-forge/issues/7291. The underlying cause of timeout errors varies depending on the message name (start-server, stop-server, or run-php). run-php indicates an error in phpGetThemeDetails and it'll be fixed by this PR (by simply not reporting those errors to Sentry anymore).

Not reporting to Sentry may seem like a non-solution, but I believe it's viable because the fact that PHP execution fails is not always within our control (it could be due to PHP-WASM problems, or issues with the WP installation, etc). We also recently improved the logic for killing unresponsive processes in #1067.

https://github.com/Automattic/dotcom-forge/issues/7291 has grouped several timeout errors, and the ones related to start-server messages will not be affected by this PR. I will create new GitHub issues for tracking those.

Testing Instructions

  1. Have a Studio site
  2. Open the appdata-v1.json file in your editor
  3. Go to wp-admin and change the theme
  4. Ensure that the themeDetails value for your site was updated correctly in appdata-v1.json

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@fredrikekelund
fredrikekelund requested a review from a team March 18, 2025 14:19
@fredrikekelund fredrikekelund self-assigned this Mar 18, 2025

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I confirm that the theme details are still working, and after changing the theme, it is saved in appData.
Great work! I'm a big fan of reducing Sentry noise.

Screenshot 2025-03-18 at 14 30 04
import SiteServerProcess from 'src/lib/site-server-process';

export const themeDetailsSchema = z.object( {
name: z.string().catch( '' ),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TIL!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I included this because it wasn't 100% clear to me if WP_Theme::get( 'Name' ) (docs) is guaranteed to return a string. It seems theoretically possible that it would also return a boolean or array. Defaulting to an empty string in those cases seemed reasonable.

Comment thread src/lib/php-get-theme-details.ts Outdated
@fredrikekelund

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @sejas! Just a quick note that I updated the PR description after realizing that this PR also fixes https://github.com/Automattic/dotcom-forge/issues/7291 (at least in part). No new testing is needed, but I wanted to bring it to your attention

Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>
@fredrikekelund

Copy link
Copy Markdown
Contributor Author

the ones related to start-server messages will not be affected by this PR. I will create new GitHub issues for tracking those.

After looking closer at STUDIO-9J and STUDIO-9Q (the issues related to creating or starting sites), I realized that they seem to only affect older releases (circa 1.2.0). So instead of opening issues to fix them, I marked the Sentry issues as resolved. We can tackle them if it turns out later they also affect new releases.

$theme = wp_get_theme();
echo json_encode([
'name' => $theme->get('Name'),
'uri' => $theme->get('ThemeURI'),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In case it wasn't already clear, we don't actually use this data. uri is not included in the StartedSiteDetails[ 'themeDetails' ] type definition.

@fredrikekelund
fredrikekelund merged commit 22f5dcd into trunk Mar 18, 2025
@fredrikekelund
fredrikekelund deleted the f26d/php-get-theme-details-improvements branch March 18, 2025 15:17
bgrgicak pushed a commit that referenced this pull request Mar 20, 2025
* Error handling improvements in `phpGetThemeDetails`

* Update src/lib/php-get-theme-details.ts

Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>

* Small tweaks

---------

Co-authored-by: Antonio Sejas <antonio.sejas@automattic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants