From df05037841f55f7bc235c8cefbad4896326cee76 Mon Sep 17 00:00:00 2001 From: Jacob Beck Date: Mon, 23 Dec 2019 11:24:59 -0700 Subject: [PATCH] improve errors on import to be more specifically correct When the error is about not being able to import the plugin, indicate that Otherwise log the original error stack trace at debug and re-raise it --- core/dbt/adapters/factory.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/dbt/adapters/factory.py b/core/dbt/adapters/factory.py index 0c8edd272c9..0742a1e0c69 100644 --- a/core/dbt/adapters/factory.py +++ b/core/dbt/adapters/factory.py @@ -46,16 +46,17 @@ def load_plugin(self, name: str) -> Type[Credentials]: # singletons try: mod = import_module('.' + name, 'dbt.adapters') - except ImportError as e: - logger.info("Error importing adapter: {}".format(e)) - raise RuntimeException( - "Could not find adapter type {}!".format(name) - ) - if not hasattr(mod, 'Plugin'): - raise RuntimeException( - f'Could not find plugin in {name} plugin module' - ) - plugin: AdapterPlugin = mod.Plugin # type: ignore + except ModuleNotFoundError as exc: + # if we failed to import the target module in particular, inform + # the user about it via a runtiem error + logger.info(f'Error importing adapter: {exc}') + if exc.name == 'dbt.adapters.' + name: + raise RuntimeException(f'Could not find adapter type {name}!') + # otherwise, the error had to have come from some underlying + # library. Log the stack trace. + logger.debug('', exc_info=True) + raise + plugin = mod.Plugin # type: AdapterPlugin plugin_type = plugin.adapter.type() if plugin_type != name: