diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2016-04-07 23:42:02 +0100 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2016-04-07 23:42:02 +0100 |
commit | 84f1525334eb3e6757ee692767301f62536da260 (patch) | |
tree | 342d70033c454b33149706e8691dc6869d16bd7f | |
parent | f9f7277f7caac4e6946217c3cd221cb1a82b8982 (diff) | |
download | external_python_setuptools-84f1525334eb3e6757ee692767301f62536da260.tar.gz external_python_setuptools-84f1525334eb3e6757ee692767301f62536da260.tar.bz2 external_python_setuptools-84f1525334eb3e6757ee692767301f62536da260.zip |
Instead of reasing a new exception, just augment the existing exception, avoiding any concerns about exception type, but still communicating the context necessary to trace the issue. Ref #537.
-rw-r--r-- | pkg_resources/__init__.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index be215ccf..ce4e7755 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -1861,8 +1861,11 @@ class FileMetadata(EmptyProvider): with io.open(self.path, encoding='utf-8') as f: try: metadata = f.read() - except UnicodeDecodeError as e: - raise Exception("Bad utf in package: %s - %s" % (self.path, e)) + except UnicodeDecodeError as exc: + # add path context to error message + tmpl = " in {self.path}" + exc.reason += tmpl.format(self=self) + raise return metadata raise KeyError("No metadata except PKG-INFO is available") |