Skip to content

Dev/errors - #162

Draft
luk384090-cloud wants to merge 8 commits into
mainfrom
dev/errors
Draft

luk384090-cloud wants to merge 8 commits into
mainfrom
dev/errors

Conversation

@luk384090-cloud

Copy link
Copy Markdown
Collaborator

Description

[Describe what this PR does and why]

Related Issue: Fixes #[issue_number] or Relates to #[issue_number]

Security Considerations: [Check if API keys or sensitive credentials are exposed in code/logs]

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Model
  • Application
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

[How to test these changes]

Additional Notes

[Optional: any other context]

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enhances error handling, response validation, and compatibility across the DashScope CLI and SDK, including mapping SDK errors to CLI-friendly codes and adding unit tests. The review feedback highlights several critical issues where the new validation logic strictly assumes dictionary outputs, which will cause runtime crashes or failures when API responses are objects. It is recommended to update these checks to dynamically support both dictionary and object formats.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashscope/cli/deployments.py Outdated
Comment thread dashscope/cli/fine_tunes.py Outdated
Comment thread dashscope/cli/fine_tunes.py Outdated
Comment thread dashscope/cli/fine_tunes.py Outdated
Comment thread dashscope/cli/agentic_rl.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/api_entities/http_request.py Outdated
Comment thread dashscope/api_entities/aiohttp_request.py Outdated
Comment thread dashscope/api_entities/aiohttp_request.py Outdated
Comment thread dashscope/api_entities/websocket_request.py Outdated
Comment thread dashscope/api_entities/aiohttp_request.py Outdated
Comment thread dashscope/api_entities/http_request.py Outdated
Comment thread dashscope/api_entities/http_request.py Outdated
Comment thread dashscope/api_entities/websocket_request.py Outdated
Comment thread dashscope/api_entities/websocket_request.py Outdated
Comment thread dashscope/api_entities/websocket_request.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread tests/integration/test_large_utf8_payload.py Outdated
Comment thread tests/integration/test_large_utf8_payload.py Outdated
Comment thread dashscope/api_entities/websocket_request.py
Comment thread dashscope/common/utils.py
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/api_entities/websocket_request.py
Comment thread dashscope/api_entities/websocket_request.py Outdated
Comment thread dashscope/api_entities/websocket_request.py
Comment thread dashscope/api_entities/websocket_request.py
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/common/utils.py
Comment thread dashscope/common/utils.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py
Comment thread test_base_address_validation.py Outdated
Comment thread test_invalid_base_url.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/finetune/reinforcement/common/errors.py Outdated
Comment thread dashscope/finetune/reinforcement/common/errors.py Outdated
Comment thread dashscope/agentstudio/exceptions.py Outdated
Comment thread dashscope/agentstudio/exceptions.py Outdated
Comment thread dashscope/api_entities/aiohttp_request.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
Comment thread dashscope/common/error_registry.py Outdated
@foleydang
foleydang force-pushed the dev/errors branch 2 times, most recently from 97af92c to 40b34b6 Compare August 7, 2026 11:16
Comment thread dashscope/agentstudio/exceptions.py Outdated

class PermissionDeniedError(APIStatusError):
code = "permission_denied_error"
code = "permission_error"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个py里面还遗留比较多的,没有定义类的。

class APIStatusError(AgentStudioError):
"""Raised when the server returns a non-2xx status."""

code = "api_status_error"

class InvalidRequestError(APIStatusError):
code = "invalid_request_error"

class AuthenticationError(APIStatusError):
code = "authentication_error"

class PermissionDeniedError(APIStatusError):
code = "permission_error"

class NotFoundError(APIStatusError):
code = "not_found_error"

class ConflictError(APIStatusError):
code = "conflict_error"

class RateLimitError(APIStatusError):
code = "rate_limit_error"

class OverloadedError(APIStatusError):
code = "overloaded_error"

class InternalServerError(APIStatusError):
code = "api_error"

Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/finetune/reinforcement/common/model.py Outdated
Comment thread dashscope/agentstudio/exceptions.py Outdated
Every failure path used to surface `code="Unknown"` with `status_code=-1`,
leaving callers unable to tell a bad request from a server fault. This routes
all of them through a single registry that separates the public code the caller
sees (`BadRequestError`, `RateLimitError`, ...) from the internal one used for
diagnosis (`sdk.agentic_rl.FunctionTestTimeout`, ...).

Public/internal split:
- Add `dashscope/common/error_registry.py` holding the public errors and the
  internal `sdk.*` definitions, each with a message, a solution and its
  substitution variables. The file is generator output; all fixes here land on
  the consumer side.
- AgentStudio and AgenticRL classify by server code only, so a status can no
  longer be contradicted by a message substring.

Classification fixes:
- `verify_function` no longer flattens `AgenticRLError` subclasses and timeouts
  into `ValidationError`, which made a failed instance query or a request
  timeout look like a 400. It also stopped discarding the reason the deployed
  function itself reported.
- Add `TimeoutErrorWithCode` deriving from the builtin `TimeoutError`, so a
  wrapped `asyncio.TimeoutError` still reaches the 504 branch on every
  supported Python version. Previously it became a 500 and the
  `sdk.agentic_rl.FunctionTestTimeout` code was unreachable.
- `AgenticRL.init()` wrapped nothing, so a bad `config_path` leaked a raw
  `IOErrorWithCode` with no `status_code` at all. A missing or malformed config
  is the caller's to fix and now reports 400.
- A WebSocket handshake 403 was reported as 401, sending callers to rotate an
  API key that was in fact valid.
- `AgenticRL.run()` logged only after passing `DashScopeException` straight
  through, which left most workflow failures unrecorded.
- The service-unavailable probe matched the bare substring "503", so an address
  such as `10.50.30.1:5030` was misread as an outage.

Detail preservation:
- Transport, WebSocket and `iter_over_async` failures keep the originating
  exception instead of replacing it with a generic 500 message. `httpx`
  timeouts usually carry no message at all, so those fall back to the type name.
- Unparsable SSE bodies report 500 and retain the payload.
- Passing a `requests.Session` to an async call silently ignored it; it now
  warns, since only an `aiohttp.ClientSession` can be reused there.

The log-and-classify sequence duplicated across five `AgenticRL` methods is
extracted into `_log_internal_error` / `_public_exception`, and the resulting
record is attributed to the calling handler rather than to the helper.

Tests: 1132 passed, 6 skipped.
The pre-commit workflow failed on `add-trailing-comma`, `black` and `pylint`,
and the 3.9 unit-test job failed on one new test.

pylint:
- `_handle_response` was at 52/50 statements. The SSE parse-failure branch it
  gained was a near-copy of the one in `call()`, so both now share
  `_sse_parse_failure_response`, which brings it back under the limit instead
  of widening it.
- Four test modules drive private request handlers on purpose; they now carry
  the module-level `protected-access` disable the other 18 test modules use.
- `test_error_detail_preserved` had a bare `yield` after `raise` purely to make
  the closure an async generator, which reads as unreachable code. It now
  yields first and raises after, matching the neighbouring test.
- `test_agentstudio_protocol` used `import dashscope.agentstudio as ...`.

Python 3.9:
- `test_record_is_attributed_to_the_caller` read `caplog.records`, which was
  empty because the SDK logger does not propagate and caplog attaches at the
  root. It now attaches a collecting handler to the module's own logger, so the
  stacklevel attribution is verified on every supported version.

Tests: 1174 passed, 6 skipped. All pre-commit hooks pass.

class InternalServerError(APIStatusError):
code = "api_error"
code = INTERNAL_ERROR.anthropic_error_code

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个check下

self,
message: str,
error_code: int = 1420,
error_code: str = "sdk.agentic_rl.FunctionLoadError",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

不是类属性,而是字符串?

@lzsweb
lzsweb marked this pull request as draft September 17, 2026 07:42
zhansheng.lzs added 2 commits September 17, 2026 16:07
Resolve conflicts in dashscope/finetune/agentic_rl.py:
- imports: union of both sides (add 'time' from main, keep 'Tuple' from dev/errors)
- test_functions except block: keep the public-error mapping from dev/errors
- keep function-instance log query/delete helpers added on main
… merge

Merging main brought in the teacher_model/PG_OPD branch into submit_job,
pushing it to 13 branches (pylint limit 12). Add an inline
'pylint: disable=too-many-branches' on submit_job, matching the existing
convention used across the SDK (transport.py, generation.py, etc.).
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