Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated general exceptions with specific ones. #3339

Merged
merged 19 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bugbug/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,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 @@ -81,7 +81,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
10 changes: 8 additions & 2 deletions bugbug/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ def get_metrics_dict() -> dict:
return metrics


class PullError(Exception):
def __init__(self, pull):
message = f"Unexpected {pull} pull"
super().__init__(message)


class Commit:
def __init__(
self,
Expand Down Expand Up @@ -731,7 +737,7 @@ def transform(hg: hglib.client, repo_dir: str, commit: Commit) -> Commit:
patch = hg.export(revs=[commit.node.encode("ascii")], git=True)
try:
patch_data = rs_parsepatch.get_lines(patch)
except Exception:
except AnalysisException:
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved
logger.error(f"Exception while analyzing {commit.node}")
raise

Expand Down Expand Up @@ -1536,7 +1542,7 @@ def trigger_pull() -> None:
raise

if p.returncode != 0:
raise Exception(
raise PullError(
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved
f"Error {p.returncode} when pulling {revision} from {branch}"
)

Expand Down
10 changes: 8 additions & 2 deletions bugbug/rust_code_analysis_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
HEADERS = {"Content-type": "application/octet-stream"}


class AnalysisException(Exception):
"""Raised when rust-code-analysis failed to analyze a file."""

pass


class RustCodeAnalysisServer:
def __init__(self, thread_num: Optional[int] = None):
for _ in range(START_RETRIES):
Expand All @@ -35,7 +41,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 AnalysisException("Unable to run rust-code-analysis server")

@property
def base_url(self):
Expand All @@ -50,7 +56,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 AnalysisException("rust-code-analysis is required for code analysis")
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -117,6 +117,12 @@
)


class UnexpectedGranularityError(Exception):
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -184,7 +190,7 @@ def rename_runnables(
for config, group in config_groups
)
else:
raise Exception(f"Unexpected {granularity} granularity")
raise UnexpectedGranularityError(f"Unexpected {granularity} granularity")
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved


def get_push_data(
Expand Down Expand Up @@ -296,7 +302,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(f"{granularity} granularity unsupported")

for obj in db.read(test_scheduling_db):
yield obj["revs"], obj["data"]
Expand All @@ -310,7 +316,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(f"{granularity} granularity unsupported")

return shelve.Shelf(
LMDBDict(past_failures_db[: -len(".tar.zst")], readonly=readonly),
Expand All @@ -325,7 +331,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(f"{granularity} granularity unsupported")

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

Expand Down
14 changes: 12 additions & 2 deletions http_service/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
BUGBUG_HTTP_SERVER = os.environ.get("BUGBUG_HTTP_SERVER", "http://localhost:8000/")


class TimeOutError(Exception):
def __init__(self, timeout):
message = f"Unexpected {timeout} timeout"
super().__init__(message)


# Test classifying a single bug.
def integration_test_single():
timeout = 1200
Expand All @@ -28,7 +34,9 @@ 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 TimeoutError(
f"Couldn't get an answer in {timeout} seconds: {response_json}"
)
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved

print("Response for bug 1376406", response_json)
assert response_json["class"] is not None
Expand All @@ -52,7 +60,9 @@ 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 TimeoutError(
f"Couldn't get an answer in {timeout} seconds: {response_json}"
)

response_1376544 = response_json["bugs"]["1376544"]
print("Response for bug 1376544", response_1376544)
Expand Down
9 changes: 8 additions & 1 deletion infra/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

import subprocess


class NotFoundError(Exception):
def __init__(self, notfound):
message = f"Unexpected {notfound} notfound"
super().__init__(message)


prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved
with open("VERSION", "r") as f:
version = f.read().rstrip()

Expand All @@ -18,7 +25,7 @@
print(e.stdout)
print("stderr:")
print(e.stderr)
raise Exception("Failure while getting latest tag")
raise NotFoundError("Failure while getting latest tag")

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

Expand Down
6 changes: 5 additions & 1 deletion scripts/commit_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def replace_first_reviewer(matchobj):
# ------------------------------------------------------------------------------


class UnsupportedReviewerError(Exception):
...


class CommitClassifier(object):
def __init__(
self,
Expand Down Expand Up @@ -329,7 +333,7 @@ def load_user(phid):
# TODO: Support group reviewers somehow.
logger.info(f"Skipping group reviewer {phid}")
else:
raise Exception(f"Unsupported reviewer {phid}")
raise UnsupportedReviewerError(f"Unsupported reviewer {phid}")
prernadabi23 marked this conversation as resolved.
Show resolved Hide resolved

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