Skip to content

Conversation

mrsdizzie
Copy link
Member

While looking into #6053 I saw two bugs:

The first is that we called touch to create a config file if it wasn't present. That doesn't work because touch can't create the parent folders when they don't exist.

The only user of this code is the alias add command which I then saw had another bug. The function for getting the path of a project config file returned null when it couldn't find one instead of false as the docblock says it should. This caused a warning later on:

PHP  15. Mustangostang\Spyc::YAMLLoad($input = NULL) /Users/isla/source/wp-cli-dev/wp-cli/php/commands/src/CLI_Alias_Command.php:358
PHP  16. Mustangostang\Spyc->_load($input = NULL) /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:118
PHP  17. Mustangostang\Spyc->loadFromSource($input = NULL) /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:440
PHP  18. Mustangostang\Spyc->loadFromString($input = NULL) /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:512
PHP  19. explode($separator = '\n', $string = NULL) /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:516

Deprecated: explode(): Passing null to parameter #2 ($string) of type string is deprecated in /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php on line 516

@mrsdizzie mrsdizzie requested a review from a team as a code owner March 6, 2025 21:30
@mrsdizzie mrsdizzie added this to the 2.12.0 milestone Mar 6, 2025
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 30.00000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Runner.php 30.00% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

Our default config file includes a path that also might not exist. Touch
can't create paths, so this silently fails in the one situation you want
it to work (when the user hasn't already created the folder).

Instead we check if the directory exists first and if not create it.
Then we use the build in touch rather than running an external command.
The DocBlock for this function says this should return sring or false
but find_file_upward actually returns null when no file is found. This
was causing a problem later on because you can't give Spyc::YAMLLoad() a
null variable.

```
PHP  15. Mustangostang\Spyc::YAMLLoad($input = NULL)
/Users/isla/source/wp-cli-dev/wp-cli/php/commands/src/CLI_Alias_Command.php:358
PHP  16. Mustangostang\Spyc->_load($input = NULL)
/Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:118
PHP  17. Mustangostang\Spyc->loadFromSource($input = NULL)
/Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:440
PHP  18. Mustangostang\Spyc->loadFromString($input = NULL)
/Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:512
PHP  19. explode($separator = '\n', $string = NULL)
/Users/isla/source/wp-cli-dev/spyc/src/Spyc.php:516

Deprecated: explode(): Passing null to parameter #2 ($string) of type
string is deprecated in /Users/isla/source/wp-cli-dev/spyc/src/Spyc.php
on line 516
```
Need to add an extra debug statement when creating a config file because
the existing debug details get overwritten and it only prints the last
one
To see if this solves current CI problems
@mrsdizzie mrsdizzie force-pushed the fix-missing-config branch from 3fc5d8d to 172ac4f Compare March 14, 2025 15:13
@swissspidy swissspidy merged commit a39513b into main Mar 14, 2025
48 of 49 checks passed
@swissspidy swissspidy deleted the fix-missing-config branch March 14, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants