drush icon indicating copy to clipboard operation
drush copied to clipboard

Fix #4039. Experiment with more terse renderException() and Collision

Open weitzman opened this issue 4 years ago • 1 comments

Here is a frankenPR which accumulates two experiments in better exception and error presentation. Lets discuss and implement the pieces that make sense.

  1. Implement \Drush\Application::renderException so that Console does not print the command help at end of each exception (e.g. sql:query [--result-file ...). This is a minimal change, and fixes the part of #4039 that I agree with.

  2. Instructs Symfony Console runner not to handle Exceptions. Now that we are responsible for presenting errors and exceptions, we use Collision. See screenshots below. This error handler is the default in Laravel. Its presentation is verbose but I think it shows helpful info. The main components

  3. Error/Exception message.

  4. A code excerpt with failing line and surrounding lines.

  5. Stack trace. 2 frames are shown by default, or all frames when in Verbose mode. Arguments are also shown, noting their types.

Some risks of Collision approach

  • I tried adding the new rendering into our existing ErrorHandler. This keeps our error levels logic the same. Note that we dont currently take over from Drupal's error handler so after bootstrap - thats another decision to make.
  • I also tried registering Collision to handle all errors and exceptions and that’s great but all of a sudden php notices stopped execution whereas in current just we log a Notice and move on even though I have E_ALL enabled.
  • Collision will be great when folks are authoring commands but a lot of Drush is running other people's commands. maybe this is too much info by default. We could look into configurable verbosity (i.e. omit code excerpt and stack trace by default) if needed.
  • Color woes - my terminal had hidden line numbers and had some less readable text until I changed to a stock iTerm theme
  • The actual code excerpt can be unhelpful but that’s life as a developer. The stack trace often points to the real fix point.
err

Below is with Verbose. Note additional stack frames in the trace.

err_vebose

weitzman avatar Feb 01 '21 03:02 weitzman

I like the direction here, but don't have any opinions on the best way to approach the challenges yet.

greg-1-anderson avatar Feb 01 '21 18:02 greg-1-anderson