Updated general exceptions with specific ones (#3339)

Fixes #3337
This commit is contained in:
Prerna Dabi 2023-03-15 04:07:07 +05:30 коммит произвёл GitHub
Родитель 8936218ab2
Коммит 48a6d79ed9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 25 добавлений и 13 удалений

Просмотреть файл

@ -193,7 +193,7 @@ class Model:
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)

Просмотреть файл

@ -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(

Просмотреть файл

@ -1536,7 +1536,7 @@ def pull(repo_dir: str, branch: str, revision: str) -> None:
raise
if p.returncode != 0:
raise Exception(
raise RuntimeError(
f"Error {p.returncode} when pulling {revision} from {branch}"
)

Просмотреть файл

@ -35,7 +35,7 @@ class RustCodeAnalysisServer:
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):
@ -50,7 +50,7 @@ class RustCodeAnalysisServer:
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:

Просмотреть файл

@ -118,6 +118,12 @@ JOBS_TO_IGNORE = (
)
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, ...]:
@ -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(
@ -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"]
@ -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),
@ -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")])

Просмотреть файл

@ -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
@ -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)

Просмотреть файл

@ -18,7 +18,7 @@ except subprocess.CalledProcessError as e:
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()

Просмотреть файл

@ -331,7 +331,7 @@ class CommitClassifier(object):
# 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]