-
Notifications
You must be signed in to change notification settings - Fork 7
feat(files): migrate filesets package to NemoClient typed HTTP client #429
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
Open
matthewgrossman
wants to merge
10
commits into
main
Choose a base branch
from
mgrossman/aircore-827-migrate-first-plugin-to-nemoclient-typed-http-client-files
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
82fb001
squash
matthewgrossman 4c69439
reduce diff
matthewgrossman 113160c
make more concise
matthewgrossman 05a8140
query params
matthewgrossman 3eb4961
lint
matthewgrossman f10ea57
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 4af5133
fix: compare SecretRef.root instead of SecretRef object against string
matthewgrossman c4b9e5e
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman 567ecac
vendor
matthewgrossman 8ea1d2c
Merge branch 'main' into mgrossman/aircore-827-migrate-first-plugin-t…
matthewgrossman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
194 changes: 113 additions & 81 deletions
194
packages/filesets/src/filesets/filesystem/filesystem.py
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/nemo_platform_plugin/src/nemo_platform_plugin/client/errors.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """HTTP error hierarchy for the NemoClient. | ||
|
|
||
| Status-code-specific subclasses also inherit from the corresponding | ||
| Stainless SDK exception so that existing ``except ConflictError`` | ||
| (imported from ``nemo_platform``) catches our exceptions too. | ||
|
|
||
| TODO: Once all consumers import from ``nemo_platform_plugin.client.errors``, | ||
| remove the Stainless base classes. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import httpx | ||
|
|
||
|
|
||
| class NemoHTTPError(Exception): | ||
| """Raised on non-2xx HTTP responses. | ||
|
|
||
| Attributes: | ||
| http_response: The raw httpx response. | ||
| status_code: The HTTP status code. | ||
| detail: A human-readable error message extracted from the response | ||
| body (``{"detail": "..."}`` convention used by FastAPI / NeMo | ||
| Platform), or the raw response text as a fallback. | ||
| body: The parsed JSON response body, or None. | ||
| """ | ||
|
|
||
| def __init__(self, http_response: httpx.Response) -> None: | ||
| self.http_response = http_response | ||
| self.status_code = http_response.status_code | ||
| self.detail = self._extract_detail(http_response) | ||
| self.body = self._extract_body(http_response) | ||
| # Call Exception.__init__ directly to avoid Stainless APIStatusError.__init__ | ||
| # which expects different arguments. Our subclasses inherit from both | ||
| # NemoHTTPError and the Stainless exception for isinstance() compatibility. | ||
| Exception.__init__(self, f"HTTP {self.status_code}: {self.detail}") | ||
|
|
||
| @staticmethod | ||
| def _extract_body(resp: httpx.Response) -> object | None: | ||
| try: | ||
| return resp.json() | ||
| except Exception: | ||
| return None | ||
|
|
||
| @staticmethod | ||
| def _extract_detail(resp: httpx.Response) -> str: | ||
| try: | ||
| body = resp.json() | ||
| if isinstance(body, dict) and isinstance(body.get("detail"), str): | ||
| return body["detail"] | ||
| except Exception: | ||
| pass | ||
| try: | ||
| return resp.text | ||
| except httpx.ResponseNotRead: | ||
| return f"HTTP {resp.status_code}" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Status-code-specific errors | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _stainless_base(name: str) -> type: | ||
| """Import a Stainless SDK exception by name, falling back to NemoHTTPError.""" | ||
| try: | ||
| import nemo_platform._exceptions as exc | ||
|
|
||
| return getattr(exc, name) | ||
| except (ImportError, AttributeError): | ||
| return NemoHTTPError | ||
|
|
||
|
|
||
| class BadRequestError(NemoHTTPError, _stainless_base("BadRequestError")): # type: ignore[misc] | ||
| """HTTP 400""" | ||
|
|
||
|
|
||
| class AuthenticationError(NemoHTTPError, _stainless_base("AuthenticationError")): # type: ignore[misc] | ||
| """HTTP 401""" | ||
|
|
||
|
|
||
| class PermissionDeniedError(NemoHTTPError, _stainless_base("PermissionDeniedError")): # type: ignore[misc] | ||
| """HTTP 403""" | ||
|
|
||
|
|
||
| class NotFoundError(NemoHTTPError, _stainless_base("NotFoundError")): # type: ignore[misc] | ||
| """HTTP 404""" | ||
|
|
||
|
|
||
| class ConflictError(NemoHTTPError, _stainless_base("ConflictError")): # type: ignore[misc] | ||
| """HTTP 409""" | ||
|
|
||
|
|
||
| class UnprocessableEntityError(NemoHTTPError, _stainless_base("UnprocessableEntityError")): # type: ignore[misc] | ||
| """HTTP 422""" | ||
|
|
||
|
|
||
| class RateLimitError(NemoHTTPError, _stainless_base("RateLimitError")): # type: ignore[misc] | ||
| """HTTP 429""" | ||
|
|
||
|
|
||
| class InternalServerError(NemoHTTPError, _stainless_base("InternalServerError")): # type: ignore[misc] | ||
| """HTTP 500+""" | ||
|
|
||
|
|
||
| _STATUS_CODE_TO_ERROR: dict[int, type[NemoHTTPError]] = { | ||
| 400: BadRequestError, | ||
| 401: AuthenticationError, | ||
| 403: PermissionDeniedError, | ||
| 404: NotFoundError, | ||
| 409: ConflictError, | ||
| 422: UnprocessableEntityError, | ||
| 429: RateLimitError, | ||
| 500: InternalServerError, | ||
| } | ||
|
|
||
|
|
||
| def raise_for_status(http_response: httpx.Response) -> None: | ||
| """Raise status-code-specific NemoHTTPError subclass for non-2xx responses.""" | ||
| if 200 <= http_response.status_code < 300: | ||
| return | ||
| error_cls = _STATUS_CODE_TO_ERROR.get(http_response.status_code, NemoHTTPError) | ||
| if error_cls is NemoHTTPError and http_response.status_code >= 500: | ||
| error_cls = InternalServerError | ||
| raise error_cls(http_response) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor
🧩 Analysis chain
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 2453
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 10147
🏁 Script executed:
Repository: NVIDIA-NeMo/nemo-platform
Length of output: 3498
exclude_unset=Truedrops default-valued request fields.CreateFilesetRequesthas defaults (purpose,metadata,custom_fields,cache), socreate_fileset()will omit them unless callers set them explicitly. If the server doesn’t reapply those defaults, POST/PUT bodies can lose data.🤖 Prompt for AI Agents