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

Catch exceptions to avoid restarting sesson #50

Open
1 task done
iandunn opened this issue Dec 5, 2020 · 3 comments
Open
1 task done

Catch exceptions to avoid restarting sesson #50

iandunn opened this issue Dec 5, 2020 · 3 comments

Comments

@iandunn
Copy link
Contributor

iandunn commented Dec 5, 2020

Feature Request

Describe your use case and the problem you are facing

Making typos/etc often results in a fatal error, and the session crashes and has to be restarted. After restarting, I have to recreate any variables, includes, etc from scratch, without making any fatal errors. That often makes it just too frustrating to use.

> wp shell
wp> require 'foo.txt';
Warning: require(foo.txt): Failed to open stream: No such file or directory in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code on line 1
Fatal error: Uncaught Error: Failed opening required 'foo.txt' (include_path='.:/usr/local/Cellar/php/8.0.0_1/share/php/pear') in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code:1
Stack trace:
#0 phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32): eval()
#1 phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/Shell_Command.php(51): WP_CLI\Shell\REPL->start()
#2 [internal function]: Shell_Command->__invoke(Array, Array)
#3 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(98): call_user_func(Array, Array, Array)
#4 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}(Array, Array)
#5 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(451): call_user_func(Object(Closure), Array, Array)
#6 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(371): WP_CLI\Dispatcher\Subcommand->invoke(Array, Array, Array)
#7 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(394): WP_CLI\Runner->run_command(Array, Array)
#8 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1160): WP_CLI\Runner->run_command_and_exit()
#9 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#10 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(74): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#11 phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(27): WP_CLI\bootstrap()
#12 phar:///usr/local/bin/wp/php/boot-phar.php(11): include('phar:///usr/loc...')
#13 /usr/local/bin/wp(4): include('phar:///usr/loc...')
#14 {main}
  thrown in phar:///usr/local/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php(32) : eval()'d code on line 1
Error: There has been a critical error on this website.Learn more about debugging in WordPress. There has been a critical error on this website.

Describe the solution you'd like

PHP's REPL is able to catch fatals and continue running:

php > $foo = 'stuff';
php > echo $foo;
stuff
php > require 'foo.txt';

Warning: require(foo.txt): Failed to open stream: No such file or directory in php shell code on line 1

Warning: Uncaught Error: Failed opening required 'foo.txt' (include_path='.:/usr/local/Cellar/php/8.0.0_1/share/php/pear') in php shell code:1
Stack trace:
#0 {main}
  thrown in php shell code on line 1
php > echo $foo;
stuff

Is that possible for wp shell ?

@iandunn
Copy link
Contributor Author

iandunn commented Dec 5, 2020

Maybe using psysh is the answer? I've searched through the code and docs, though, and don't see anything about how to get wp shell to use it.

I eventually found #11, maybe that should be reconsidered? At the very least, put a link to that package in this repo's readme and wp help docs would go a long way.

@iandunn
Copy link
Contributor Author

iandunn commented Dec 5, 2020

I think making that package official and enabled by default would be a good devex improvement.

@schlessera
Copy link
Member

Yes, this is something that annoys me as well. I guess it shouldn't;t be too hard to add an exception handler clause to the internal loop...?

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

No branches or pull requests

3 participants