Skip to content

Commit

Permalink
feature(ruff): add blind except (BLE) checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fruch committed Jun 2, 2024
1 parent 1a721d6 commit a220bcd
Show file tree
Hide file tree
Showing 99 changed files with 335 additions and 337 deletions.
2 changes: 1 addition & 1 deletion artifacts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def get_email_data(self):
email_data = self._get_common_email_data()
try:
node = self.node
except Exception: # pylint: disable=broad-except
except (ValueError, IndexError):
node = None
if node:
scylla_packages = node.scylla_packages_installed
Expand Down
2 changes: 1 addition & 1 deletion docker/alternator-dns/dns_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def livenodes_update():
# If we're successful, replace livenodes by the new list
livenodes = a
print(livenodes)
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except # noqa: BLE001
# TODO: contacting this ip was unsuccessful, maybe we should
# remove it from the list of live nodes.
pass
Expand Down
2 changes: 1 addition & 1 deletion functional_tests/scylla_operator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _bring_cluster_back_to_original_state(
db_cluster.restart_scylla()
db_cluster.wait_for_nodes_up_and_normal(
nodes=db_cluster.nodes, verification_node=db_cluster.nodes[0])
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
tester.healthy_flag = False
pytest.fail("Failed to bring cluster nodes back to original state due to :\n" +
"".join(traceback.format_exception(type(exc), exc, exc.__traceback__)))
Expand Down
4 changes: 2 additions & 2 deletions functional_tests/scylla_operator/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def wait_for_cleanup_logs(log_follower_name, log_follower, db_cluster):
time.sleep(4)
db_cluster.nodes[0].run_cqlsh(cmd=f"DROP KEYSPACE IF EXISTS {current_ks_name}", timeout=60)
time.sleep(4)
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
# NOTE: we don't care if some of the queries fail.
# At first, there are redundant ones and, at second, they are utilitary.
log.warning("Utilitary CQL query has failed: %s", exc)
Expand Down Expand Up @@ -646,7 +646,7 @@ def change_cluster_spec() -> None:
# NOTE: increase the value only when the sysctl spec update is successful
# to avoid false negative results in further assertions
expected_aio_max_nr_value += 1
except Exception as error: # pylint: disable=broad-except
except Exception as error: # pylint: disable=broad-except # noqa: BLE001
str_error = str(error)
log.debug("Change /spec/sysctls value to %d failed. Error: %s",
expected_aio_max_nr_value, str_error)
Expand Down
6 changes: 1 addition & 5 deletions longevity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,9 @@ def _flush_all_nodes(self):

def get_email_data(self):
self.log.info("Prepare data for email")
email_data = {}
grafana_dataset = {}

try:
email_data = self._get_common_email_data()
except Exception as error: # pylint: disable=broad-except
self.log.exception("Error in gathering common email data: Error:\n%s", error, exc_info=error)
email_data = self._get_common_email_data()

try:
grafana_dataset = self.monitors.get_grafana_screenshot_and_snapshot(
Expand Down
2 changes: 1 addition & 1 deletion performance_regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def display_results(self, results, test_name=''):
with open(os.path.join(self.logdir, 'jenkins_perf_PerfPublisher.xml'), 'w', encoding="utf-8") as pref_file:
content = """<report name="%s report" categ="none">%s</report>""" % (test_name, test_xml)
pref_file.write(content)
except Exception as ex: # pylint: disable=broad-except
except Exception as ex: # pylint: disable=broad-except # noqa: BLE001
self.log.debug('Failed to display results: {0}'.format(results))
self.log.debug('Exception: {0}'.format(ex))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.ruff]
lint.select = ["PL"]
lint.select = ["PL", "YTT", "BLE"]

lint.ignore = ["E501", "PLR2004"]

Expand Down
10 changes: 5 additions & 5 deletions sct.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def _run_yaml_test(backend, full_path, env):
config = SCTConfiguration()
config.verify_configuration()
config.check_required_files()
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
output.append(''.join(traceback.format_exception(type(exc), exc, exc.__traceback__)))
error = True
return error, output
Expand All @@ -815,7 +815,7 @@ def lint_yamls(backend, exclude: str, include: str): # pylint: disable=too-many
continue
try:
exclude_filters.append(re.compile(flt))
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
raise ValueError(f'Exclude filter "{flt}" compiling failed with: {exc}') from exc

include_filters = []
Expand All @@ -824,7 +824,7 @@ def lint_yamls(backend, exclude: str, include: str): # pylint: disable=too-many
continue
try:
include_filters.append(re.compile(flt))
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
raise ValueError(f'Include filter "{flt}" compiling failed with: {exc}') from exc

original_env = {**os.environ}
Expand Down Expand Up @@ -965,7 +965,7 @@ def show_monitor(test_id, date_time, kill, cluster_name):
containers = {}
try:
containers = restore_monitoring_stack(test_id, date_time)
except Exception as details: # pylint: disable=broad-except
except Exception as details: # pylint: disable=broad-except # noqa: BLE001
LOGGER.error(details)

if not containers:
Expand Down Expand Up @@ -1348,7 +1348,7 @@ def send_email(test_id=None, test_status=None, start_time=None, started_by=None,
sys.exit(1)
try:
reporter.send_report(test_results)
except Exception: # pylint: disable=broad-except
except Exception: # pylint: disable=broad-except # noqa: BLE001
LOGGER.error("Failed to create email due to the following error:\n%s", traceback.format_exc())
build_reporter("TestAborted", email_recipients, testrun_dir).send_report({
"job_url": os.environ.get("BUILD_URL"),
Expand Down
2 changes: 1 addition & 1 deletion sdcm/cassandra_harry_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _run_stress(self, loader, loader_idx, cpu_idx):
retry=0,
)
result = self._parse_harry_summary(docker_run_result.stdout.splitlines())
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
errors_str = format_stress_cmd_error(exc)
if "timeout" in errors_str:
event_type = CassandraHarryEvent.timeout
Expand Down
2 changes: 1 addition & 1 deletion sdcm/cdclog_reader_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _run_stress(self, loader, loader_idx, cpu_idx): # pylint: disable=unused-ar
stress_cmd=self.stress_cmd,
errors=result.stderr.split("\n")).publish()
return result
except Exception as exc: # pylint: disable=broad-except
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
CDCReaderStressEvent.failure(node=loader,
stress_cmd=self.stress_cmd,
errors=[format_stress_cmd_error(exc), ]).publish()
Expand Down
Loading

0 comments on commit a220bcd

Please sign in to comment.