Skip to content

Commit f166d3d

Browse files
author
luk384090-cloud
committed
refactor(error): add deprecation markers to 1.x error classes
- Added @deprecated decorator to mark all 1.x error classes - Created _legacy_error utility function to handle deprecation warnings uniformly - Preserved backward compatibility; existing except clauses continue to work - Guided users toward the new dashscope.errors (2.0) exception hierarchy - Added deprecation docstrings to all error classes
1 parent 34bc6c8 commit f166d3d

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎dashscope/legacy_1x/common/error.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,115 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
3+
"""The 1.x exception family (pending deprecation).
4+
5+
Every class here belongs to the 1.x API surface and is *going to be*
6+
deprecated along with it: instantiation emits a
7+
:exc:`PendingDeprecationWarning` (ignored by Python's default filters,
8+
so current 1.x users see no noise), and static checkers flag the names
9+
via ``__deprecated__``. New code should use the 2.0 family in
10+
:mod:`dashscope.errors` (``DashScopeError`` and its subclasses). The
11+
1.x classes stay fully supported and importable so existing ``except``
12+
clauses keep working.
13+
14+
``DashScopeException`` carries no marker at all: it is re-exported from
15+
the neutral layer (:mod:`dashscope._shared._errors`) that both stacks
16+
inherit from.
17+
"""
18+
19+
from typing_extensions import deprecated
320

421
# The base class lives in the neutral layer so the AgentStudio sub-SDK
522
# (owned by the 2.0 package) and the 1.x classes below inherit from one
623
# and the same object.
724
from dashscope._shared._errors import DashScopeException
825

926

27+
def _legacy_error(name):
28+
"""Pending-deprecation marker for one 1.x error class.
29+
30+
Warns on instantiation (and subclasses), never on import, so the
31+
SDK's own 1.x modules can keep importing these names silently.
32+
"""
33+
return deprecated(
34+
f"dashscope.common.error.{name} is part of the 1.x API, which "
35+
f"is scheduled for deprecation and will be removed in a future "
36+
f"release; use the dashscope.errors (2.0) exception family "
37+
f"instead.",
38+
category=PendingDeprecationWarning,
39+
)
40+
41+
42+
@_legacy_error("AuthenticationError")
1043
class AuthenticationError(DashScopeException):
1144
pass
1245

1346

47+
@_legacy_error("InvalidParameter")
1448
class InvalidParameter(DashScopeException):
1549
pass
1650

1751

52+
@_legacy_error("InvalidTask")
1853
class InvalidTask(DashScopeException):
1954
pass
2055

2156

57+
@_legacy_error("UnsupportedModel")
2258
class UnsupportedModel(DashScopeException):
2359
pass
2460

2561

62+
@_legacy_error("UnsupportedTask")
2663
class UnsupportedTask(DashScopeException):
2764
pass
2865

2966

67+
@_legacy_error("ModelRequired")
3068
class ModelRequired(DashScopeException):
3169
pass
3270

3371

72+
@_legacy_error("InvalidModel")
3473
class InvalidModel(DashScopeException):
3574
pass
3675

3776

77+
@_legacy_error("InvalidInput")
3878
class InvalidInput(DashScopeException):
3979
pass
4080

4181

82+
@_legacy_error("InvalidFileFormat")
4283
class InvalidFileFormat(DashScopeException):
4384
pass
4485

4586

87+
@_legacy_error("UnsupportedApiProtocol")
4688
class UnsupportedApiProtocol(DashScopeException):
4789
pass
4890

4991

92+
@_legacy_error("NotImplemented")
5093
class NotImplemented(DashScopeException): # pylint: disable=redefined-builtin
5194
pass
5295

5396

97+
@_legacy_error("MultiInputsWithBinaryNotSupported")
5498
class MultiInputsWithBinaryNotSupported(DashScopeException):
5599
pass
56100

57101

102+
@_legacy_error("UnexpectedMessageReceived")
58103
class UnexpectedMessageReceived(DashScopeException):
59104
pass
60105

61106

107+
@_legacy_error("UnsupportedData")
62108
class UnsupportedData(DashScopeException):
63109
pass
64110

65111

112+
@_legacy_error("AssistantError")
66113
class AssistantError(DashScopeException):
67114
def __init__(self, **kwargs):
68115
self.message = None
@@ -88,6 +135,7 @@ def __str__(self):
88135

89136

90137
# for server send generation or inference error.
138+
@_legacy_error("RequestFailure")
91139
class RequestFailure(DashScopeException):
92140
def __init__(
93141
self,
@@ -111,37 +159,46 @@ def __str__(self):
111159
return msg
112160

113161

162+
@_legacy_error("UnknownMessageReceived")
114163
class UnknownMessageReceived(DashScopeException):
115164
pass
116165

117166

167+
@_legacy_error("InputDataRequired")
118168
class InputDataRequired(DashScopeException):
119169
pass
120170

121171

172+
@_legacy_error("InputRequired")
122173
class InputRequired(DashScopeException):
123174
pass
124175

125176

177+
@_legacy_error("UnsupportedDataType")
126178
class UnsupportedDataType(DashScopeException):
127179
pass
128180

129181

182+
@_legacy_error("ServiceUnavailableError")
130183
class ServiceUnavailableError(DashScopeException):
131184
pass
132185

133186

187+
@_legacy_error("UnsupportedHTTPMethod")
134188
class UnsupportedHTTPMethod(DashScopeException):
135189
pass
136190

137191

192+
@_legacy_error("AsyncTaskCreateFailed")
138193
class AsyncTaskCreateFailed(DashScopeException):
139194
pass
140195

141196

197+
@_legacy_error("UploadFileException")
142198
class UploadFileException(DashScopeException):
143199
pass
144200

145201

202+
@_legacy_error("TimeoutException")
146203
class TimeoutException(DashScopeException):
147204
pass

0 commit comments

Comments
 (0)