Skip to content

Fix uses of 'Plugin not found' string #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 13, 2024

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Nov 13, 2024

I replied to a comment from @gordonrjones (maybe the same GitHub username?) on the WordPress support forum:

There are three possible locations where this error could be coming from:

return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'performance-lab' ) );

return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'performance-lab' ) );

return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'default' ) );

All three are in that same file: includes/admin/plugins.php. Unfortunately we’re reusing the same string for each error. Are you comfortable editing the strings in the plugin file editor in WordPress to, for example, add __LINE__ after the strings so we can differentiate between them? This will help us debug where the error is coming from.

Aside: I also see that we’re using the string with the default text domain once, but with the performance-lab text domain twice. That’s not good either. I’ll open a PR to fix this for the next release, as well as to make the strings unique.

This PR seeks to improve the usage of the strings, including their disambiguation.

The error message now includes an "error code" which is the line number from where the error originated:

image

@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only labels Nov 13, 2024
@westonruter westonruter added this to the performance-lab 3.6.0 milestone Nov 13, 2024
@westonruter westonruter marked this pull request as ready for review November 13, 2024 00:12
Copy link

github-actions bot commented Nov 13, 2024

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: felixarntz <flixos90@git.wordpress.org>

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

$transient_key = 'perflab_plugins_info-v2';
$transient_key = 'perflab_plugins_info';
Copy link
Member Author

Choose a reason for hiding this comment

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

This was changed in #1613 to account for the format change. Since the transient only lasts for 1 day anyway, we can now restore the original transient key.

@@ -359,8 +369,13 @@ function perflab_install_and_activate_plugin( string $plugin_slug, array &$proce
}

$plugins = get_plugins( '/' . $plugin_slug );
if ( empty( $plugins ) ) {
return new WP_Error( 'plugin_not_found', __( 'Plugin not found.', 'default' ) );
if ( count( $plugins ) === 0 ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The replacement of empty() with count() is part of #1219

'plugin_not_found',
__( 'Plugin not found.', 'default' ) . ' ' .
/* translators: %s is error code */
sprintf( '(Error code: %d)', __LINE__ )
Copy link
Member

Choose a reason for hiding this comment

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

I find the "error code" terminology confusing. It makes me think this is either an HTTP response code or an actual error code I can look up in some docs. Why not say "line"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. Done in 49cb889

Co-authored-by: felixarntz <flixos90@git.wordpress.org>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@westonruter On second thought, I think it would be better to provide contextual error messages. Providing which line an error was triggered seems a bit too low-level and points to the messages themselves not being helpful enough. Error lines should come from stack traces etc., it doesn't feel right to include them in the messages arbitrarily.

This means we can't use a Core translation string anymore, but that's not necessarily a bad thing. @swissspidy had mentioned somewhere else before that that's a bit fragile to do anyway (e.g. because Core strings can change, outside of our control).

I left suggestions for ways to make the messages more helpful below.

Co-authored-by: Felix Arntz <felixarntz@google.com>
@westonruter westonruter merged commit 2bec0e8 into trunk Nov 13, 2024
14 checks passed
@westonruter westonruter deleted the fix/plugin-not-found-disambiguation branch November 13, 2024 16:48
@westonruter
Copy link
Member Author

Build for testing (3.6.0-alpha): performance-lab.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Performance Lab Issue relates to work in the Performance Lab Plugin only [Type] Bug An existing feature is broken
Projects
Status: Done 😃
Development

Successfully merging this pull request may close these issues.

2 participants