Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Fix issue #880 - more useful message to user when %paste fails #999

merged 2 commits into from

2 participants


When tkinter is not installed and '%paste' is run, the user is now prompted to install it.

Initializes TryNext exception in CommandChainDispatcher with args/kwargs to present a message to the user with the traceback.

@mattrco mattrco Fix issue #880 - initialize TryNext with args and kwargs.
Presents a message to the user along with the traceback prompting them to install tkinter.

Thanks, Matt. I think it would be good to also catch this exception in magic_paste (see here), and just print an error message instead of showing an unhelpful traceback.


Sounds good - and I'll also clean up the message. Still getting to grips with the codebase somewhat.


No worries - part of the idea behind quickfix bugs is to get new people into the code.


@MattCottingham: Have you had a chance to have another look at this? Don't worry if not.


@takluyver, afraid I haven't had a chance this week - but I will have more time this coming week. Though if somebody else would like to fix it don't let this block them :)


@takluyver, I've made a quick update to catch the exception in magic_paste. If an error message is provided, that is printed. Otherwise, if no other details are provided, a more generic message is printed.

In some ways I'd like to re-raise in magic_paste and handle the exception in the caller, but I realise that's not quite how TryNext is used across the project.

Any suggestions for improvement welcome!

@takluyver takluyver merged commit 205731a into ipython:master

That's great. Don't worry, we don't generally raise exceptions from magic_* functions.

I've made one tiny change, so the error is a little bit tidier (213b5ed), and merged it.

@damianavila damianavila referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2011
  1. @mattrco

    Fix issue #880 - initialize TryNext with args and kwargs.

    mattrco committed
    Presents a message to the user along with the traceback prompting them to install tkinter.
Commits on Nov 21, 2011
  1. @mattrco
This page is out of date. Refresh to see the latest.
2  IPython/core/
@@ -138,7 +138,7 @@ def __call__(self,*args, **kw):
args = exc.args
kw = exc.kwargs
# if no function will accept it, raise TryNext up to the caller
- raise TryNext
+ raise TryNext(*args, **kw)
def __str__(self):
return str(self.chain)
15 IPython/frontend/terminal/
@@ -34,7 +34,7 @@
from IPython.utils import py3compat
from IPython.utils.terminal import toggle_set_term_title, set_term_title
from IPython.utils.process import abbrev_cwd
-from IPython.utils.warn import warn
+from IPython.utils.warn import warn, error
from IPython.utils.text import num_ini_spaces
from IPython.utils.traitlets import Int, CBool, Unicode
@@ -611,9 +611,16 @@ def magic_paste(self, parameter_s=''):
if opts.has_key('r'):
- text =
- block = self._strip_pasted_lines_for_code(text.splitlines())
+ try:
+ text =
+ block = self._strip_pasted_lines_for_code(text.splitlines())
+ except TryNext as clipboard_exc:
+ message = getattr(clipboard_exc, 'args')
+ if message:
+ error(message)
+ else:
+ error('Could not get text from the clipboard.')
+ return
# By default, echo back to terminal unless quiet mode is requested
if not opts.has_key('q'):
Something went wrong with that request. Please try again.