Skip to content
This repository

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

Merged
merged 2 commits into from over 2 years ago

2 participants

Matt Cottingham Thomas Kluyver
Matt Cottingham

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.

Matt Cottingham Fix issue #880 - initialize TryNext with args and kwargs.
Presents a message to the user along with the traceback prompting them to install tkinter.
14d011c
Thomas Kluyver
Collaborator

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.

Matt Cottingham

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

Thomas Kluyver
Collaborator

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

Thomas Kluyver
Collaborator

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

Matt Cottingham

@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 :)

Thomas Kluyver
Collaborator
Matt Cottingham

@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!

Thomas Kluyver takluyver merged commit 205731a into from November 21, 2011
Thomas Kluyver takluyver closed this November 21, 2011
Thomas Kluyver
Collaborator

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.

Damián Avila damianavila referenced this pull request from a commit July 30, 2013
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

Showing 2 unique commits by 1 author.

Nov 14, 2011
Matt Cottingham Fix issue #880 - initialize TryNext with args and kwargs.
Presents a message to the user along with the traceback prompting them to install tkinter.
14d011c
Nov 21, 2011
Matt Cottingham Catch clipboard exception in magic_paste and print error message 205731a
This page is out of date. Refresh to see the latest.
2  IPython/core/hooks.py
@@ -138,7 +138,7 @@ def __call__(self,*args, **kw):
138 138
                     args = exc.args
139 139
                     kw = exc.kwargs
140 140
         # if no function will accept it, raise TryNext up to the caller
141  
-        raise TryNext
  141
+        raise TryNext(*args, **kw)
142 142
 
143 143
     def __str__(self):
144 144
         return str(self.chain)
15  IPython/frontend/terminal/interactiveshell.py
@@ -34,7 +34,7 @@
34 34
 from IPython.utils import py3compat
35 35
 from IPython.utils.terminal import toggle_set_term_title, set_term_title
36 36
 from IPython.utils.process import abbrev_cwd
37  
-from IPython.utils.warn import warn
  37
+from IPython.utils.warn import warn, error
38 38
 from IPython.utils.text import num_ini_spaces
39 39
 from IPython.utils.traitlets import Int, CBool, Unicode
40 40
 
@@ -611,9 +611,16 @@ def magic_paste(self, parameter_s=''):
611 611
         if opts.has_key('r'):
612 612
             self._rerun_pasted()
613 613
             return
614  
-
615  
-        text = self.shell.hooks.clipboard_get()
616  
-        block = self._strip_pasted_lines_for_code(text.splitlines())
  614
+        try:
  615
+            text = self.shell.hooks.clipboard_get()
  616
+            block = self._strip_pasted_lines_for_code(text.splitlines())
  617
+        except TryNext as clipboard_exc:
  618
+            message = getattr(clipboard_exc, 'args')
  619
+            if message:
  620
+                error(message)
  621
+            else:
  622
+                error('Could not get text from the clipboard.')
  623
+            return
617 624
 
618 625
         # By default, echo back to terminal unless quiet mode is requested
619 626
         if not opts.has_key('q'):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.