From 200a760b96f799fa26da295d7842ffb0bdbc3136 2011-10-08 22:31:42 From: MinRK Date: 2011-10-08 22:31:42 Subject: [PATCH] avoid interpreting IOError in config file as file-not-found adds ConfigFileNotFound exception class for this case --- diff --git a/IPython/config/application.py b/IPython/config/application.py index 261e816..3723fff 100644 --- a/IPython/config/application.py +++ b/IPython/config/application.py @@ -27,7 +27,7 @@ from copy import deepcopy from IPython.config.configurable import SingletonConfigurable from IPython.config.loader import ( - KVArgParseConfigLoader, PyFileConfigLoader, Config, ArgumentError + KVArgParseConfigLoader, PyFileConfigLoader, Config, ArgumentError, ConfigFileNotFound, ) from IPython.utils.traitlets import ( @@ -370,8 +370,8 @@ class Application(SingletonConfigurable): loader = PyFileConfigLoader(filename, path=path) try: config = loader.load_config() - except IOError: - # problem with the file (probably doesn't exist), raise + except ConfigFileNotFound: + # problem finding the file, raise raise except Exception: # try to get the full filename, but it will be empty in the diff --git a/IPython/config/loader.py b/IPython/config/loader.py index 1b97d11..588251f 100644 --- a/IPython/config/loader.py +++ b/IPython/config/loader.py @@ -34,10 +34,12 @@ from IPython.utils import py3compat, text, warn class ConfigError(Exception): pass - class ConfigLoaderError(ConfigError): pass +class ConfigFileNotFound(ConfigError): + pass + class ArgumentError(ConfigLoaderError): pass @@ -258,7 +260,10 @@ class PyFileConfigLoader(FileConfigLoader): def load_config(self): """Load the config from a file and return it as a Struct.""" self.clear() - self._find_file() + try: + self._find_file() + except IOError as e: + raise ConfigFileNotFound(str(e)) self._read_file_as_dict() self._convert_to_config() return self.config @@ -297,7 +302,7 @@ class PyFileConfigLoader(FileConfigLoader): loader = PyFileConfigLoader(fname, path) try: sub_config = loader.load_config() - except IOError: + except ConfigFileNotFound: # Pass silently if the sub config is not there. This happens # when a user s using a profile, but not the default config. pass