drush icon indicating copy to clipboard operation
drush copied to clipboard

pm-uninstall with a module that's not currently installed should give an info message, not an exception

Open joachim-n opened this issue 2 years ago • 5 comments

Describe the bug

If I do drush pmu oops_this_module_was_not_enabled_anyway I get:

In PmCommands.php line 177:

  The following module(s) are not installed: layout_builder_admin_theme. No modules to uninstall.

The presence of the line number and file makes it look like a handled exception. This is unnecessarily scary.

It should be a 'Nothing to do' style info message.

To Reproduce What did you do?

Expected behavior

An info-level message.

Actual behavior Exception.

Workaround Is there another way to do the desired action?

System Configuration

Q A
Drush version? 11.5.1
Drupal version? 9.5
PHP version 8.1
OS? Mac

Additional information Add any other context about the problem here.

joachim-n avatar Jun 05 '23 13:06 joachim-n

Pretty sure this is a dupe

weitzman avatar Jun 06 '23 03:06 weitzman

I did a search for 'uninstall' and didn't find anything, though it's possible the dupe is reported differently because it's about deeper internals.

joachim-n avatar Jun 06 '23 05:06 joachim-n

I dont see a dupe either ... I could go either way on this. I thin the current way is equally valid. Given that, I'm inclined to preserve backward compat and keep status quo. Leaving this open for more input.

weitzman avatar Jun 07 '23 13:06 weitzman

I don't really want to institute rules along the lines of whether any given function may or may not throw an exception based on how the user perceives the consequences of that exception. This is just to preserve our sanity e.g. for highly-nested methods.

One thing I think we could do, though, is introduce "scary" and "not so scary" named exceptions; e.g. we could throw new \NotScaryUserException("Nothing to do");, and then catch that exception type and print a less-scary-looking error message. If this action did not alter the status result code (non-scary errors are still status code 1), then this could perhaps be done in a backwards-compatible way.

greg-1-anderson avatar Jun 07 '23 14:06 greg-1-anderson

then catch that exception type and print a less-scary-looking error message

That's what I was thinking, yes.

Generally, bad user input shouldn't produce an exception (that the user sees). The same way that inputting bad data into a form should give a message, not a crash.

joachim-n avatar Jun 09 '23 09:06 joachim-n