From f2bf1c124a512a2c27b4abe221991933d5c7c59b Mon Sep 17 00:00:00 2001
From: Jeremy Fee <jmfee@usgs.gov>
Date: Wed, 1 Nov 2017 15:05:42 -0600
Subject: [PATCH] Use specific exception types

---
 bin/geomag.py                       | 2 +-
 bin/main.py                         | 2 +-
 bin/monitor.py                      | 2 +-
 geomagio/StreamConverter.py         | 4 ++--
 geomagio/WebService.py              | 4 ++--
 geomagio/edge/LocationCode.py       | 2 +-
 geomagio/iaga2002/IAGA2002Parser.py | 2 +-
 gruntconfig/flake8.js               | 4 ++--
 8 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/bin/geomag.py b/bin/geomag.py
index 84e786883..0682db176 100755
--- a/bin/geomag.py
+++ b/bin/geomag.py
@@ -5,7 +5,7 @@ import sys
 # ensure geomag is on the path before importing
 try:
     import geomagio  # noqa (tells linter to ignore this line.)
-except:
+except ImportError:
     script_dir = path.dirname(path.abspath(__file__))
     sys.path.append(path.normpath(path.join(script_dir, '..')))
 
diff --git a/bin/main.py b/bin/main.py
index 5cf6dbdef..40be09ea3 100755
--- a/bin/main.py
+++ b/bin/main.py
@@ -5,7 +5,7 @@ import sys
 # ensure geomag is on the path before importing
 try:
     import geomagio  # noqa (ignores this line for lint purposes.)
-except:
+except ImportError:
     script_dir = path.dirname(path.abspath(__file__))
     sys.path.append(path.normpath(path.join(script_dir, '..')))
 
diff --git a/bin/monitor.py b/bin/monitor.py
index 012bcd68e..7e636abda 100755
--- a/bin/monitor.py
+++ b/bin/monitor.py
@@ -6,7 +6,7 @@ import sys
 # ensure geomag is on the path before importing
 try:
     import geomagio  # noqa (tells linter to ignore this line.)
-except:
+except ImportError:
     script_dir = path.dirname(path.abspath(__file__))
     sys.path.append(path.normpath(path.join(script_dir, '..')))
 
diff --git a/geomagio/StreamConverter.py b/geomagio/StreamConverter.py
index f0ff48b64..d2e65e47b 100644
--- a/geomagio/StreamConverter.py
+++ b/geomagio/StreamConverter.py
@@ -276,7 +276,7 @@ def __get_obs_d_from_obs(obs):
     """
     try:
         d = obs.select(channel='D')[0]
-    except:
+    except IndexError:
         h = obs.select(channel='H')[0]
         e = obs.select(channel='E')[0]
         d = __get_trace('D', e.stats,
@@ -301,7 +301,7 @@ def __get_obs_e_from_obs(obs):
     """
     try:
         e = obs.select(channel='E')[0]
-    except:
+    except IndexError:
         h = obs.select(channel='H')[0]
         d = obs.select(channel='D')[0]
         e = __get_trace('E', d.stats,
diff --git a/geomagio/WebService.py b/geomagio/WebService.py
index 416381a36..a06a7181c 100644
--- a/geomagio/WebService.py
+++ b/geomagio/WebService.py
@@ -238,7 +238,7 @@ class WebService(object):
         else:
             try:
                 starttime = UTCDateTime(starttime)
-            except:
+            except TypeError:
                 raise WebServiceException(
                         'Bad starttime value "%s".'
                         ' Valid values are ISO-8601 timestamps.' % starttime)
@@ -247,7 +247,7 @@ class WebService(object):
         else:
             try:
                 endtime = UTCDateTime(endtime)
-            except:
+            except TypeError:
                 raise WebServiceException(
                         'Bad endtime value "%s".'
                         ' Valid values are ISO-8601 timestamps.' % endtime)
diff --git a/geomagio/edge/LocationCode.py b/geomagio/edge/LocationCode.py
index aa5168eb8..0cbafd391 100644
--- a/geomagio/edge/LocationCode.py
+++ b/geomagio/edge/LocationCode.py
@@ -27,6 +27,6 @@ def LocationCode(code):
     """
     try:
         return re.match('^[A-Z0-9]{2}$', code).group(0)
-    except:
+    except AttributeError:
         raise argparse.ArgumentTypeError(
                 'Invalid location code, expected /^[A-Z0-9]{2}$/')
diff --git a/geomagio/iaga2002/IAGA2002Parser.py b/geomagio/iaga2002/IAGA2002Parser.py
index 917411bd2..b0604d22d 100644
--- a/geomagio/iaga2002/IAGA2002Parser.py
+++ b/geomagio/iaga2002/IAGA2002Parser.py
@@ -108,7 +108,7 @@ class IAGA2002Parser(object):
                     value = 1 / float(value.replace('second', '').strip())
                 elif value.find('Hz') != -1:
                     value = float(value.replace('Hz', '').strip())
-            except:
+            except ValueError:
                 return
         elif key_upper == 'DATA INTERVAL TYPE':
             key = 'data_interval_type'
diff --git a/gruntconfig/flake8.js b/gruntconfig/flake8.js
index 38805efbd..2c664c628 100644
--- a/gruntconfig/flake8.js
+++ b/gruntconfig/flake8.js
@@ -3,7 +3,7 @@
 module.exports = {
   src: {
     options: {
-      ignore: ['E122', 'E126', 'E127', 'E128', 'E131']
+      ignore: ['E122', 'E126', 'E127', 'E128', 'E131', 'E741']
     },
     src: [
       'bin/*.py',
@@ -13,7 +13,7 @@ module.exports = {
 
   test: {
     options: {
-      ignore: ['E122', 'E126', 'E127', 'E128', 'E131']
+      ignore: ['E122', 'E126', 'E127', 'E128', 'E131', 'E741']
     },
     src: [
       'test/**/*.py'
-- 
GitLab