Skip to content

Commit 0428080

Browse files
committed
Fix:Error message for invalid task ID
1 parent 954a43a commit 0428080

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515
- Compatibility with `xarray>=2025.03`.
16+
- Error message for invalid task ID.
1617

1718
## [2.8.1] - 2025-03-20
1819

Diff for: tests/test_web/test_webapi.py

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
upload,
4040
)
4141
from tidy3d.web.core.environment import Env
42+
from tidy3d.web.core.exceptions import TaskNotFoundError
4243
from tidy3d.web.core.types import TaskType
4344

4445
TASK_NAME = "task_name_test"
@@ -722,3 +723,18 @@ def save_sim_to_path(path: str) -> None:
722723
"--inspect_sim",
723724
]
724725
)
726+
727+
728+
@responses.activate
729+
def test_load_invalid_task_raises(mock_webapi):
730+
"""Ensure that load() raises TaskNotFoundError for a non-existent task ID."""
731+
fake_id = "INVALID_TASK_ID"
732+
733+
responses.add(
734+
responses.GET,
735+
f"{Env.current.web_api_endpoint}/tidy3d/tasks/{fake_id}/detail",
736+
json={"error": "Task not found"},
737+
status=404,
738+
)
739+
with pytest.raises(TaskNotFoundError, match="does not exist"):
740+
load(fake_id)

Diff for: tidy3d/web/core/exceptions.py

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ def __init__(self, message: str = None):
1111
log = get_logger()
1212
super().__init__(message)
1313
log.error(message)
14+
15+
16+
class TaskNotFoundError(WebError):
17+
"""Raised when a requested task ID does not exist on the server."""
18+
19+
pass

Diff for: tidy3d/web/core/http_util.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from .core_config import get_logger
2727
from .environment import Env
28-
from .exceptions import WebError
28+
from .exceptions import TaskNotFoundError, WebError
2929

3030
REINITIALIZED = False
3131

@@ -131,7 +131,9 @@ def wrapper(*args, **kwargs):
131131

132132
if resp.status_code != ResponseCodes.OK.value:
133133
if resp.status_code == ResponseCodes.NOT_FOUND.value:
134-
return None
134+
raise TaskNotFoundError(
135+
"The requested task ID does not exist. Please verify your task ID."
136+
)
135137
json_resp = resp.json()
136138
if "error" in json_resp.keys():
137139
raise WebError(json_resp["error"])

0 commit comments

Comments
 (0)