From ce530ca448ecb38eb9c75e27105277651e0d6bda 2014-10-16 19:14:34 From: Min RK Date: 2014-10-16 19:14:34 Subject: [PATCH] Merge pull request #6087 from minrk/better-error-no-connection-file Raise better IOError if a connection file is not found --- diff --git a/IPython/parallel/client/client.py b/IPython/parallel/client/client.py index 26c185d..5fec363 100644 --- a/IPython/parallel/client/client.py +++ b/IPython/parallel/client/client.py @@ -27,7 +27,7 @@ from IPython.utils.capture import RichOutput from IPython.utils.coloransi import TermColors from IPython.utils.jsonutil import rekey, extract_dates, parse_date from IPython.utils.localinterfaces import localhost, is_local_ip -from IPython.utils.path import get_ipython_dir +from IPython.utils.path import get_ipython_dir, compress_user from IPython.utils.py3compat import cast_bytes, string_types, xrange, iteritems from IPython.utils.traitlets import (HasTraits, Integer, Instance, Unicode, Dict, List, Bool, Set, Any) @@ -47,6 +47,7 @@ from .view import DirectView, LoadBalancedView # Decorators for Client methods #-------------------------------------------------------------------------- + @decorator def spin_first(f, self, *args, **kwargs): """Call spin() to sync state prior to calling the method.""" @@ -58,6 +59,10 @@ def spin_first(f, self, *args, **kwargs): # Classes #-------------------------------------------------------------------------- +_no_connection_file_msg = """ +Failed to connect because no Controller could be found. +Please double-check your profile and ensure that a cluster is running. +""" class ExecuteReply(RichOutput): """wrapper for finished Execute results""" @@ -382,6 +387,11 @@ class Client(HasTraits): self._setup_profile_dir(self.profile, profile_dir, ipython_dir) + no_file_msg = '\n'.join([ + "You have attempted to connect to an IPython Cluster but no Controller could be found.", + "Please double-check your configuration and ensure that a cluster is running.", + ]) + if self._cd is not None: if url_file is None: if not cluster_id: @@ -389,10 +399,19 @@ class Client(HasTraits): else: client_json = 'ipcontroller-%s-client.json' % cluster_id url_file = pjoin(self._cd.security_dir, client_json) + if not os.path.exists(url_file): + msg = '\n'.join([ + "Connection file %r not found." % compress_user(url_file), + no_file_msg, + ]) + raise IOError(msg) if url_file is None: - raise ValueError( - "I can't find enough information to connect to a hub!" - " Please specify at least one of url_file or profile." + raise IOError(no_file_msg) + + if not os.path.exists(url_file): + # Connection file explicitly specified, but not found + raise IOError("Connection file %r not found. Is a controller running?" % \ + compress_user(url_file) ) with open(url_file) as f: