Skip to content
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

[CLI] Set debug constants during boot #1983

Merged
merged 2 commits into from
Nov 5, 2024
Merged

Conversation

bgrgicak
Copy link
Collaborator

@bgrgicak bgrgicak commented Nov 4, 2024

This PR sets the WordPress debug constants during the CLI boot.

Depending on the --debug flag, WP_DEBUG, and WP_DEBUG_LOG will be set to true or false during boot.
The WP_DEBUG_DISPLAY constant will always be set to false to match the Website behavior.

Disabling WP_DEBUG_DISPLAY will also avoid crashing the CLI during boot if a plugin activation fails. Long-term #1979 shouldn't crash Playground anymore, but we still want these constant defaults in the CLI.

Testing Instructions (or ideally a Blueprint)

  • Store this blueprint on your machine
{
  "steps": [
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "wordpress.org/plugins",
        "slug": "002-ps-custom-post-type"
      },
      "options": {
        "activate": true
      }
    }
  ]
}
  • Start the CLI with the blueprint (change the BLUEPRINT_PATH to match your path)
bun ./packages/playground/cli/src/cli.ts server --debug --blueprint BLUEPRINT_PATH

@bgrgicak bgrgicak requested a review from a team November 4, 2024 10:01
@bgrgicak bgrgicak self-assigned this Nov 4, 2024
Copy link
Member

@brandonpayton brandonpayton left a comment

Choose a reason for hiding this comment

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

I left a question about WP_DEBUG_DISPLAY, but this looks good and tests well to me. Thanks, Bero!

{
WP_DEBUG: args.debug,
WP_DEBUG_LOG: args.debug,
WP_DEBUG_DISPLAY: false,
Copy link
Member

Choose a reason for hiding this comment

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

In your experience, is this something that most people prefer to disable? It's not clear to me that I'd want it disabled if running with the --debug flag because having messages printing in-page might be the feedback that is easiest to access.

Copy link
Collaborator Author

@bgrgicak bgrgicak Nov 5, 2024

Choose a reason for hiding this comment

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

WP_DEBUG_DISPLAY is rarely enabled. It literally prints all error levels into the HTML and most of the time messes up the page.

But now when I think of it, the point of the debug flag is to control the displaying of logs and not data collection.

I will set these the same way we do on the Website and users can always override them using Blueprints.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the debug flag description. It shouldn't control logging.

'Return PHP error log content if an error occurs while building the site.',

Copy link
Collaborator

Choose a reason for hiding this comment

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

What does "return" mean in this context? It's not a function return

Copy link
Collaborator

@adamziel adamziel Nov 5, 2024

Choose a reason for hiding this comment

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

And let's update the description to clarify this – is the --debug flag only effective at build time? Or does it also affect the runtime or the built site later on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok!

is the --debug flag only effective at build time? Or does it also affect the runtime or the built site later on?

Only during the build, but it would be nice for it to also return errors during runtime.

Copy link
Collaborator

Choose a reason for hiding this comment

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

By "return" do you mean "print"? Or "save to file"? Or something else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's printing, thanks for the questions, they help narrow down what's missing in the text.
Here is an improved version https://github.com/WordPress/wordpress-playground/pull/1985/files#diff-ff00c9c03a9587a4ac648349850e14a53fdd62418bce04573537c9c794c95811R107

@bgrgicak bgrgicak merged commit 61199e2 into trunk Nov 5, 2024
10 checks passed
@bgrgicak bgrgicak deleted the add/cli-debug-constants branch November 5, 2024 06:17
@@ -215,7 +215,6 @@ async function run() {
php: args.php as SupportedPHPVersion,
wp: args.wp,
},
login: args.login,
Copy link
Collaborator

@adamziel adamziel Nov 5, 2024

Choose a reason for hiding this comment

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

What happened here? Why remove this @bgrgicak ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was causing errors and it's not supported anymore since we changed the way login works. Should I open an issue to add login support?

We have an option to login users with CLI, but it requires a specific URL parameter (playground_force_auto_login_as_user), we could print this in the CLI output and enable users to login that way.

Copy link
Collaborator

@adamziel adamziel Nov 5, 2024

Choose a reason for hiding this comment

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

Couldn't login work the same way as on Playground web?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

PR to fix login #1985

@adamziel
Copy link
Collaborator

adamziel commented Nov 5, 2024

I like having a --debug option, thank you @bgrgicak. I have concerns about the details and I left some comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants