Skip to content

Commit

Permalink
Updated general exceptions with specific ones (#3339)
Browse files Browse the repository at this point in the history
Fixes #3337
  • Loading branch information
prernadabi23 committed Mar 14, 2023
1 parent 8936218 commit 48a6d79
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bugbug/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_human_readable_feature_names(self):
elif type_ == "text":
feature_name = f"Combined text contains '{feature_name}'"
elif type_ not in ("data", "couple_data"):
raise Exception(f"Unexpected feature type for: {full_feature_name}")
raise ValueError(f"Unexpected feature type for: {full_feature_name}")

cleaned_feature_names.append(feature_name)

Expand Down
2 changes: 1 addition & 1 deletion bugbug/models/testselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_cost(config: str) -> int:
if all(s in config for s in substrings):
return cost

raise Exception(f"Couldn't find cost for {config}")
raise ValueError(f"Couldn't find cost for {config}")


def _generate_equivalence_sets(
Expand Down
2 changes: 1 addition & 1 deletion bugbug/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ def trigger_pull() -> None:
raise

if p.returncode != 0:
raise Exception(
raise RuntimeError(
f"Error {p.returncode} when pulling {revision} from {branch}"
)

Expand Down
4 changes: 2 additions & 2 deletions bugbug/rust_code_analysis_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, thread_num: Optional[int] = None):
time.sleep(0.35)

self.terminate()
raise Exception("Unable to run rust-code-analysis server")
raise RuntimeError("Unable to run rust-code-analysis server")

@property
def base_url(self):
Expand All @@ -50,7 +50,7 @@ def start_process(self, thread_num: Optional[int] = None):
cmd += ["-j", str(thread_num)]
self.proc = subprocess.Popen(cmd)
except FileNotFoundError:
raise Exception("rust-code-analysis is required for code analysis")
raise RuntimeError("rust-code-analysis is required for code analysis")

def terminate(self):
if self.proc is not None:
Expand Down
14 changes: 10 additions & 4 deletions bugbug/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
)


class UnexpectedGranularityError(ValueError):
def __init__(self, granularity):
message = f"Unexpected {granularity} granularity"
super().__init__(message)


def filter_runnables(
runnables: tuple[Runnable, ...], all_runnables: Set[Runnable], granularity: str
) -> tuple[Any, ...]:
Expand Down Expand Up @@ -185,7 +191,7 @@ def rename_runnables(
for config, group in config_groups
)
else:
raise Exception(f"Unexpected {granularity} granularity")
raise UnexpectedGranularityError(granularity)


def get_push_data(
Expand Down Expand Up @@ -298,7 +304,7 @@ def get_test_scheduling_history(granularity):
elif granularity == "config_group":
test_scheduling_db = TEST_CONFIG_GROUP_SCHEDULING_DB
else:
raise Exception(f"{granularity} granularity unsupported")
raise UnexpectedGranularityError(granularity)

for obj in db.read(test_scheduling_db):
yield obj["revs"], obj["data"]
Expand All @@ -312,7 +318,7 @@ def get_past_failures(granularity, readonly):
elif granularity == "config_group":
past_failures_db = os.path.join("data", PAST_FAILURES_CONFIG_GROUP_DB)
else:
raise Exception(f"{granularity} granularity unsupported")
raise UnexpectedGranularityError(granularity)

return shelve.Shelf(
LMDBDict(past_failures_db[: -len(".tar.zst")], readonly=readonly),
Expand All @@ -327,7 +333,7 @@ def get_failing_together_db_path(granularity: str) -> str:
elif granularity == "config_group":
path = FAILING_TOGETHER_CONFIG_GROUP_DB
else:
raise Exception(f"{granularity} granularity unsupported")
raise UnexpectedGranularityError(granularity)

return os.path.join("data", path[: -len(".tar.zst")])

Expand Down
10 changes: 8 additions & 2 deletions http_service/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def integration_test_single():
response_json = response.json()

if not response.ok:
raise Exception(f"Couldn't get an answer in {timeout} seconds: {response_json}")
raise requests.HTTPError(
f"Couldn't get an answer in {timeout} seconds: {response_json}",
response=response,
)

logger.info("Response for bug 1376406 %s", response_json)
assert response_json["class"] is not None
Expand All @@ -56,7 +59,10 @@ def integration_test_batch():
response_json = response.json()

if not response.ok:
raise Exception(f"Couldn't get an answer in {timeout} seconds: {response_json}")
raise requests.HTTPError(
f"Couldn't get an answer in {timeout} seconds: {response_json}",
response=response,
)

response_1376544 = response_json["bugs"]["1376544"]
logger.info("Response for bug 1376544 %s", response_1376544)
Expand Down
2 changes: 1 addition & 1 deletion infra/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
print(e.stdout)
print("stderr:")
print(e.stderr)
raise Exception("Failure while getting latest tag")
raise RuntimeError("Failure while getting latest tag")

cur_tag = p.stdout.decode("utf-8")[1:].rstrip()

Expand Down
2 changes: 1 addition & 1 deletion scripts/commit_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def load_user(phid):
# TODO: Support group reviewers somehow.
logger.info("Skipping group reviewer %s", phid)
else:
raise Exception(f"Unsupported reviewer {phid}")
raise ValueError(f"Unsupported reviewer {phid}")

for patch in needed_stack:
revision = revisions[patch.phid]
Expand Down

0 comments on commit 48a6d79

Please sign in to comment.