Skip to content

Commit 0a30409

Browse files
fix: replace 32 bare except clauses with except Exception
1 parent 9524b56 commit 0a30409

19 files changed

Lines changed: 32 additions & 32 deletions

File tree

.test-infra/metrics/sync/github/sync.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def initDBConnection():
9999
conn = psycopg2.connect(
100100
f"dbname='{DB_NAME}' user='{DB_USER_NAME}' host='{DB_HOST}'"
101101
f" port='{DB_PORT}' password='{DB_PASSWORD}'")
102-
except:
102+
except Exception:
103103
print('Failed to connect to DB; retrying in 1 minute')
104104
sys.stdout.flush()
105105
time.sleep(60)
@@ -452,7 +452,7 @@ def fetchNewData():
452452
data = None
453453
try:
454454
data = jsonData["data"]["search"]["edges"]
455-
except:
455+
except Exception:
456456
# TODO This means that API returned error.
457457
# We might want to bring this to stderr or utilize other means of logging.
458458
# Examples: we hit throttling, etc

.test-infra/metrics/sync/jenkins/syncjenkins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def initConnection():
7575
try:
7676
conn = psycopg2.connect(f"dbname='{dbname}' user='{dbusername}' host='{host}'"
7777
f" port='{port}' password='{dbpassword}'")
78-
except:
78+
except Exception:
7979
print('Failed to connect to DB; retrying in 1 minute')
8080
time.sleep(60)
8181
return conn

contributor-docs/discussion-docs/generate_doc_md.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def convert_to_timestamp(date_string):
123123
date_format = "%a, %d %b %Y %H:%M:%S %z"
124124
datetime_obj = datetime.datetime.strptime(date_string, date_format)
125125
return datetime_obj.timestamp()
126-
except:
126+
except Exception:
127127
return None
128128

129129

@@ -238,7 +238,7 @@ def find_google_docs_links(mbox_file, doc_messages, doc_urls):
238238
title = get_google_doc_title(doc_url)
239239
try:
240240
sender = extract_name_re(str(message["From"]))
241-
except:
241+
except Exception:
242242
print("Something is wrong: ", message["From"])
243243
sender = None
244244
if not sender:

learning/tour-of-beam/learning-content/common-transforms/motivating-challenge/python-challenge/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def tryParseTaxiRideCost(line,index):
5656
if(len(line) > index):
5757
try:
5858
yield float(line[index])
59-
except:
59+
except Exception:
6060
yield float(0)
6161
else:
6262
yield float(0)

learning/tour-of-beam/learning-content/common-transforms/motivating-challenge/python-solution/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def tryParseTaxiRideCost(line,index):
5656
if(len(line) > index):
5757
try:
5858
yield float(line[index])
59-
except:
59+
except Exception:
6060
yield float(0)
6161
else:
6262
yield float(0)

learning/tour-of-beam/learning-content/triggers/motivating-challenge/python-challenge/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def tryParseTaxiRideCost(line,index):
6060
if(len(line) > index):
6161
try:
6262
yield float(line[index])
63-
except:
63+
except Exception:
6464
yield float(0)
6565
else:
6666
yield float(0)

learning/tour-of-beam/learning-content/triggers/motivating-challenge/python-solution/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def tryParseTaxiRideCost(line,index):
6060
if(len(line) > index):
6161
try:
6262
yield float(line[index])
63-
except:
63+
except Exception:
6464
yield float(0)
6565
else:
6666
yield float(0)

learning/tour-of-beam/learning-content/windowing/motivating-challenge/python-challenge/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def tryParseTaxiRideCost(line,index):
5757
if(len(line) > index):
5858
try:
5959
yield float(line[index])
60-
except:
60+
except Exception:
6161
yield float(0)
6262
else:
6363
yield float(0)

learning/tour-of-beam/learning-content/windowing/motivating-challenge/python-solution/task.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def tryParseTaxiRideCost(line,index):
5656
if(len(line) > index):
5757
try:
5858
yield float(line[index])
59-
except:
59+
except Exception:
6060
yield float(0)
6161
else:
6262
yield float(0)

sdks/java/container/license_scripts/pull_licenses_java.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def pull_source_code(base_url, dir_name, dep):
144144
try:
145145
soup = BeautifulSoup(urlopen(Request(base_url, headers={
146146
'User-Agent': 'Apache Beam'})).read(), "html.parser")
147-
except:
147+
except Exception:
148148
logging.error('Error reading source base from {base_url}'.format(base_url=base_url))
149149
raise
150150
source_count = 0
@@ -173,7 +173,7 @@ def write_to_csv(csv_list):
173173
writer.writeheader()
174174
for data in csv_list:
175175
writer.writerow(data)
176-
except:
176+
except Exception:
177177
traceback.print_exc()
178178
raise
179179

@@ -210,10 +210,10 @@ def execute(dep):
210210
# pull license
211211
try:
212212
license_url = dep_config[name][version]['license']
213-
except:
213+
except Exception:
214214
try:
215215
license_url = dep['moduleLicenseUrl']
216-
except:
216+
except Exception:
217217
# url cannot be found, add to no_licenses and skip to pull.
218218
with thread_lock:
219219
no_licenses.append(name_version)
@@ -230,12 +230,12 @@ def execute(dep):
230230
try:
231231
notice_url = dep_config[name][version]['notice']
232232
pull_from_url(dir_name + '/NOTICE', notice_url, name_version)
233-
except:
233+
except Exception:
234234
pass
235235
else:
236236
try:
237237
license_url = dep['moduleLicenseUrl']
238-
except:
238+
except Exception:
239239
license_url = ''
240240
logging.debug(
241241
'License/notice for {name_version} were pulled automatically.'.
@@ -244,10 +244,10 @@ def execute(dep):
244244
# get license_type to decide if pull source code.
245245
try:
246246
license_type = dep['moduleLicense']
247-
except:
247+
except Exception:
248248
try:
249249
license_type = dep_config[name][version]['type']
250-
except:
250+
except Exception:
251251
license_type = 'no_license_type'
252252
with thread_lock:
253253
no_license_type.append(name_version)
@@ -256,7 +256,7 @@ def execute(dep):
256256
if any(x in license_type.lower() for x in SOURCE_CODE_REQUIRED_LICENSES):
257257
try:
258258
base_url = dep_config[name][version]['source']
259-
except:
259+
except Exception:
260260
module = dep['moduleName'].split(':')[0].replace('.', '/')
261261
base_url = maven_url_temp.format(module=module + '/' + name,
262262
version=version)
@@ -281,7 +281,7 @@ def read_cached_licenses():
281281
try:
282282
CACHED_LICENSES=set(os.listdir(cached_license_path))
283283
logging.info("Read %d licenses from cache.", len(CACHED_LICENSES))
284-
except:
284+
except Exception:
285285
logging.warning("Error occurred when reading cached licenses.")
286286
traceback.print_exc()
287287

0 commit comments

Comments
 (0)