diff options
author | Armin Rigo <arigo@tunes.org> | 2017-03-10 15:03:17 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2017-03-10 15:03:17 +0100 |
commit | 0fd2b8f93c1d0d9fd08ab4f0bd01dc3500ff0b48 (patch) | |
tree | 174fdec70bae59f289be3975bc47493866c2af19 | |
parent | 632e2a148feb226d84d7ac40c7045b610a4c3539 (diff) | |
download | cffi-0fd2b8f93c1d0d9fd08ab4f0bd01dc3500ff0b48.tar.gz |
Improve the error message
-rw-r--r-- | cffi/api.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/cffi/api.py b/cffi/api.py index 92b7628..6250f20 100644 --- a/cffi/api.py +++ b/cffi/api.py @@ -756,21 +756,27 @@ class FFI(object): def _load_backend_lib(backend, name, flags): + import os if name is None: if sys.platform != "win32": return backend.load_library(None, flags) name = "c" # Windows: load_library(None) fails, but this works # (backward compatibility hack only) - try: - if '.' not in name and '/' not in name: - raise OSError("library not found: %r" % (name,)) - return backend.load_library(name, flags) - except OSError: - import ctypes.util - path = ctypes.util.find_library(name) - if path is None: - raise # propagate the original OSError - return backend.load_library(path, flags) + first_error = None + if '.' in name or '/' in name or os.sep in name: + try: + return backend.load_library(name, flags) + except OSError as e: + first_error = e + import ctypes.util + path = ctypes.util.find_library(name) + if path is None: + msg = ("ctypes.util.find_library() did not manage " + "to locate a library called %r" % (name,)) + if first_error is not None: + msg = "%s. Additionally, %s" % (first_error, msg) + raise OSError(msg) + return backend.load_library(path, flags) def _make_ffi_library(ffi, libname, flags): backend = ffi._backend |