Prevent prefilter from crashing IPython #415

Merged
merged 2 commits into from May 9, 2011

Conversation

Projects
None yet
3 participants
Owner

minrk commented May 4, 2011

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.

Closes #216

Contributor

rkern commented May 4, 2011

Why except SystemExit: instead of except Exception:?

Owner

minrk commented May 4, 2011

Because I managed to commit while I was checking that the test I added failed when the exception wasn't caught.

Fixed now.

Owner

takluyver commented May 5, 2011

Looks good to me. I'll test it later.

Owner

takluyver commented May 5, 2011

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?

Owner

minrk commented May 5, 2011

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.

Contributor

rkern commented May 5, 2011

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:

Owner

takluyver commented May 5, 2011

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.

@minrk minrk short error message on AliasError in run_cell
instead of full traceback

use prefilter_failed flag to prevent duplicate code
2bcbe90
Owner

minrk commented May 5, 2011

Okay, now the message is just the short 'ERROR: ' on AliasErrors, but all exceptions are caught.

Owner

takluyver commented May 5, 2011

OK, looks good to me.

minrk merged commit 285a7f7 into ipython:master May 9, 2011

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