stecman / symfony-console-completion

Automatic tab-key completion for Symfony console application options, arguments and parameters
MIT License
421 stars 26 forks source link

Suppress exceptions #10

Closed pjcdawkins closed 9 years ago

pjcdawkins commented 9 years ago

It's quite disruptive to see an exception on the command line while auto-completion is running. Exceptions should be suppressed somehow.

Obviously this could happen inside the callback itself. However, doing it inside Completion::run() seems appropriate - for my use case, the suppression is only necessary during auto-completion, so the integration code is full of try/catch blocks.

pjcdawkins commented 9 years ago

The library is awesome by the way!

stecman commented 9 years ago

Hey @pjcdawkins, I agree that the way exceptions are presented at the moment is pretty gnarly, but I'm a little hesitant to suppress them totally by default as it would silence feedback when there is a real problem in the program; not ideal for dev/debugging or letting users know something broke. In my opinion this kind of total suppression belongs in user code where specific exceptions can be targeted.

In your case it looks like you might be able to just wrap your $this->handler->runCompletion() call in a try/catch to avoid all of the try/catch blocks inside completion callbacks. The callbacks are only ever called inside of runCompletion(), so there's nowhere else their exceptions need to be caught. Would that work for you?


Regarding the presentation of exceptions during completion, it would be nice as a single-line message by default (instead of the 10 lines of help and whitespace rendered currently), with an option to generate a shell hook in verbose mode so that full stack traces could be shown. This would just need a small amend to handle non-verbose output from CompletionCommand::runCompletion here.

$ program [tab] [tab]
Error: [exception message]
pjcdawkins commented 9 years ago

That makes sense. If I come up with something I'll make another PR