Skip to content

Commit 420b66d

Browse files
abhishekmadan30ahal
authored andcommitted
fix: Updated Error Type to TaskclusterRestFailure to align with the switch to the taskcluster package
1 parent 3a80bed commit 420b66d

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

src/taskgraph/actions/cancel.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import requests
99

10+
from taskcluster import TaskclusterRestFailure
1011
from taskgraph.util.taskcluster import cancel_task
1112

1213
from .registry import register_callback_action
@@ -27,8 +28,14 @@ def cancel_action(parameters, graph_config, input, task_group_id, task_id):
2728
# only cancel tasks with the level-specific schedulerId.
2829
try:
2930
cancel_task(task_id)
30-
except requests.HTTPError as e:
31-
if e.response.status_code == 409:
31+
except (requests.HTTPError, TaskclusterRestFailure) as e:
32+
status_code = None
33+
if isinstance(e, requests.HTTPError):
34+
status_code = e.response.status_code if e.response else None
35+
elif isinstance(e, TaskclusterRestFailure):
36+
status_code = e.status_code
37+
38+
if status_code == 409:
3239
# A 409 response indicates that this task is past its deadline. It
3340
# cannot be cancelled at this time, but it's also not running
3441
# anymore, so we can ignore this error.

src/taskgraph/actions/cancel_all.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import requests
1111

12+
from taskcluster import TaskclusterRestFailure
1213
from taskgraph.util.taskcluster import (
1314
CONCURRENCY,
1415
cancel_task,
@@ -36,8 +37,14 @@ def do_cancel_task(task_id):
3637
logger.info(f"Cancelling task {task_id}")
3738
try:
3839
cancel_task(task_id)
39-
except requests.HTTPError as e:
40-
if e.response.status_code == 409:
40+
except (requests.HTTPError, TaskclusterRestFailure) as e:
41+
status_code = None
42+
if isinstance(e, requests.HTTPError):
43+
status_code = e.response.status_code if e.response else None
44+
elif isinstance(e, TaskclusterRestFailure):
45+
status_code = e.status_code
46+
47+
if status_code == 409:
4148
# A 409 response indicates that this task is past its deadline. It
4249
# cannot be cancelled at this time, but it's also not running
4350
# anymore, so we can ignore this error.

src/taskgraph/actions/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from functools import reduce
1212

1313
from requests.exceptions import HTTPError
14+
from taskcluster.exceptions import TaskclusterRestFailure
1415

1516
from taskgraph import create
1617
from taskgraph.decision import read_artifact, rename_artifact, write_artifact
@@ -36,7 +37,7 @@ def fetch_graph_and_labels(parameters, graph_config, task_group_id=None):
3637
try:
3738
# Look up the decision_task id in the index
3839
decision_task_id = find_decision_task(parameters, graph_config)
39-
except KeyError:
40+
except (KeyError, TaskclusterRestFailure):
4041
if not task_group_id:
4142
raise
4243
# Not found (e.g. from github-pull-request), fall back to the task group id.

src/taskgraph/optimize/strategies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
from datetime import datetime
33

4+
from taskcluster.exceptions import TaskclusterRestFailure
5+
46
from taskgraph.optimize.base import OptimizationStrategy, register_strategy
57
from taskgraph.util.path import match as match_path
68
from taskgraph.util.taskcluster import find_task_id, status_task
@@ -64,7 +66,7 @@ def should_replace_task(self, task, params, deadline, arg):
6466
continue
6567

6668
return task_id
67-
except KeyError:
69+
except (KeyError, TaskclusterRestFailure):
6870
# go on to the next index path
6971
pass
7072

src/taskgraph/util/taskcluster.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,15 @@ def get_ancestors(task_ids: Union[list[str], str]) -> dict[str, str]:
476476
for task_id in task_ids:
477477
try:
478478
task_def = get_task_definition(task_id)
479-
except requests.HTTPError as e:
479+
except (requests.HTTPError, taskcluster.TaskclusterRestFailure) as e:
480480
# Task has most likely expired, which means it's no longer a
481481
# dependency for the purposes of this function.
482-
if e.response.status_code == 404:
483-
continue
482+
if isinstance(e, requests.HTTPError):
483+
if e.response and e.response.status_code == 404:
484+
continue
485+
elif isinstance(e, taskcluster.TaskclusterRestFailure):
486+
if e.status_code == 404:
487+
continue
484488
raise e
485489

486490
dependencies = task_def.get("dependencies", [])

0 commit comments

Comments
 (0)