Since user code can be executed in the prefilter step (e.g. via Aliases), catch and print those errors like normal code.
I could also be less aggressive and only catch AliasErrors.
Why except SystemExit: instead of except Exception:?
prevent errors in prefilter from crashing IPython
Because I managed to commit while I was checking that the test I added failed when the exception wasn't caught.
Looks good to me. I'll test it later.
That's working here. Is it worth catching the specific case (wrong number of arguments for an alias) and displaying a short error message, rather than the full traceback?
If we want IPython to die at every other error, I can only catch the AliasError. I don't actually think that's a good idea, but it would conform with current practices of making IPython crash and exit at the first sign of unrecognized trouble.
I think IPython should only crash when something is unrecoverable, not at every possible bug in IPython, but that's something of a separate issue.
I think he's suggesting that you catch the AliasError specifically to make a more focused error message, then catch the rest of the exceptions with the general except Exception:
As Robert says - I'm not suggesting you remove the general except handler. Just that, in addition, I'd prefer to avoid a traceback of IPython internals for a simple mistake in user code. E.g. for magic functions, if the user's command is wrong in some way, we often just print a single line explanation of the problem, and return from the function.
short error message on AliasError in run_cell
instead of full traceback
use prefilter_failed flag to prevent duplicate code
Okay, now the message is just the short 'ERROR: ' on AliasErrors, but all exceptions are caught.
OK, looks good to me.