Skip to content

Commit 4b86ad2

Browse files
Merge pull request swiftlang#1571 from practicalswift/fix-blind-excepts
[Python] Fix blind "except:" statements
2 parents c237762 + e2de5c2 commit 4b86ad2

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def log_results(log_directory, driver, formatted_output, swift_repo=None):
128128
"""
129129
try:
130130
branch = get_current_git_branch(swift_repo)
131-
except:
131+
except (OSError, subprocess.CalledProcessError):
132132
branch = None
133133
timestamp = time.strftime("%Y%m%d%H%M%S", time.localtime())
134134
if branch:
@@ -138,7 +138,7 @@ def log_results(log_directory, driver, formatted_output, swift_repo=None):
138138
driver_name = os.path.basename(driver)
139139
try:
140140
os.makedirs(output_directory)
141-
except:
141+
except OSError:
142142
pass
143143
log_file = os.path.join(output_directory,
144144
driver_name + '-' + timestamp + '.log')

benchmark/scripts/Benchmark_RuntimeLeaksRunner.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
7777
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
7878
p.wait()
7979
error_out = p.stderr.readlines()
80-
except:
80+
except OSError:
8181
print("Child Process Failed! (%s,%s)" % (data['path'], data['test_name']))
8282
return LeaksRunnerResult(test_name, True)
8383

@@ -94,7 +94,7 @@ class LeaksRunnerBenchmarkDriver(perf_test_driver.BenchmarkDriver):
9494
d['objc_count'] -= FUNC_TO_GLOBAL_COUNTS[data['test_name']]['objc_count']
9595

9696
return LeaksRunnerResult(test_name, (d['objc_count'] + d['swift_count']) > 0)
97-
except:
97+
except (KeyError, ValueError):
9898
print "Failed parse output! (%s,%s)" % (data['path'], data['test_name'])
9999
return LeaksRunnerResult(test_name, True)
100100

benchmark/scripts/compare_perf_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
def parse_int(word):
3939
try:
4040
return int(word)
41-
except:
41+
except ValueError:
4242
raise Exception("Expected integer value, not " + word)
4343

4444
def get_scores(fname):

tools/SourceKit/bindings/python/sourcekitd/capi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, wrapped):
4747
self.wrapped = wrapped
4848
try:
4949
self.__doc__ = wrapped.__doc__
50-
except:
50+
except AttributeError:
5151
pass
5252

5353
def __get__(self, instance, instance_type=None):

utils/submit-benchmark-results

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def submit_results_to_server(results_data, submit_url):
6464
# The result is expected to be a JSON object.
6565
try:
6666
return json.loads(result_data)
67-
except:
67+
except ValueError:
6868
import traceback
6969
print("Unable to load result, not a valid JSON object.")
7070
print()

0 commit comments

Comments
 (0)