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

Fix:Error message for invalid task ID #2345

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

rahul-flex
Copy link
Contributor

Previously, when web.load received a 404 response for an invalid or non-existent task ID, the client would return None and produce unhelpful error messages. This commit changes that behavior: it now raises a TaskNotFoundError with a clear, user-friendly explanation.
Screenshot 2025-03-31 at 11 22 56 PM

@rahul-flex rahul-flex requested a review from yaugenst-flex April 1, 2025 03:23
@rahul-flex rahul-flex force-pushed the rahul-flex/webapi-errors branch from b55cbb0 to 0428080 Compare April 1, 2025 17:39
Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rahul-flex! This is going in the right direction but we should try to handle 404 errors more generally.

Comment on lines 134 to 136
raise TaskNotFoundError(
"The requested task ID does not exist. Please verify your task ID."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much more general than not finding a task. Any request that returns a 404 status code will be caught here, so this should also raise a more generic exception. Maybe something like WebNotFoundError(WebError).

The error then needs to be handled properly by the caller. We can focus on tasks for now since that was the original intention. A good place to catch this is probably in tidy3d/web/core/task_core.py

@rahul-flex rahul-flex force-pushed the rahul-flex/webapi-errors branch from 61f4c3b to d46649b Compare April 1, 2025 19:20
@rahul-flex
Copy link
Contributor Author

Updated error message:
Screenshot 2025-04-01 at 8 47 36 PM

@rahul-flex rahul-flex requested a review from yaugenst-flex April 2, 2025 00:47
Comment on lines 16 to 19
class TaskNotFoundError(WebError):
"""Raised when a requested task ID does not exist on the server."""

pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in principle i'm not opposed to having a fine grained error like this but on the other hand it seems like just raising a WebNotFoundError should be fine. so maybe remove this one?

Comment on lines 266 to 267
except WebNotFoundError:
raise TaskNotFoundError(f"The requested task ID '{task_id}' does not exist.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd probably do the following instead:

except WebNotFoundError as e:
  td.log.error("error message")
  raise e

@yaugenst-flex
Copy link
Collaborator

Closes #2154

Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rahul-flex looks good to go from my side, minus the little changelog clarification.

@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `fill` and `fill_structures` argument in `td.Simulation.plot_structures()` and `td.Simulation.plot()` respectively to disable fill and plot outlines of structures only.
- New subpixel averaging option `ContourPathAveraging` applied to dielectric material boundaries.

### Changed
- Error message for invalid task ID.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved error message and handling when attempting to load a non-existent task ID.

@yaugenst-flex yaugenst-flex requested a review from QingengWei April 4, 2025 07:05
@yaugenst-flex
Copy link
Collaborator

@QingengWei could you have a look? This addresses the discussion in #2154. The http_interceptor now raises an error on 404 instead of returning None, which means that the API should now be able to return 404 status which we then need to handle properly here on the client.

The old if resp is None checks are still in place to keep compatibility but I think we should move to returning "normal" status codes on the API side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants