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.
724from 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" )
1043class AuthenticationError (DashScopeException ):
1144 pass
1245
1346
47+ @_legacy_error ("InvalidParameter" )
1448class InvalidParameter (DashScopeException ):
1549 pass
1650
1751
52+ @_legacy_error ("InvalidTask" )
1853class InvalidTask (DashScopeException ):
1954 pass
2055
2156
57+ @_legacy_error ("UnsupportedModel" )
2258class UnsupportedModel (DashScopeException ):
2359 pass
2460
2561
62+ @_legacy_error ("UnsupportedTask" )
2663class UnsupportedTask (DashScopeException ):
2764 pass
2865
2966
67+ @_legacy_error ("ModelRequired" )
3068class ModelRequired (DashScopeException ):
3169 pass
3270
3371
72+ @_legacy_error ("InvalidModel" )
3473class InvalidModel (DashScopeException ):
3574 pass
3675
3776
77+ @_legacy_error ("InvalidInput" )
3878class InvalidInput (DashScopeException ):
3979 pass
4080
4181
82+ @_legacy_error ("InvalidFileFormat" )
4283class InvalidFileFormat (DashScopeException ):
4384 pass
4485
4586
87+ @_legacy_error ("UnsupportedApiProtocol" )
4688class UnsupportedApiProtocol (DashScopeException ):
4789 pass
4890
4991
92+ @_legacy_error ("NotImplemented" )
5093class NotImplemented (DashScopeException ): # pylint: disable=redefined-builtin
5194 pass
5295
5396
97+ @_legacy_error ("MultiInputsWithBinaryNotSupported" )
5498class MultiInputsWithBinaryNotSupported (DashScopeException ):
5599 pass
56100
57101
102+ @_legacy_error ("UnexpectedMessageReceived" )
58103class UnexpectedMessageReceived (DashScopeException ):
59104 pass
60105
61106
107+ @_legacy_error ("UnsupportedData" )
62108class UnsupportedData (DashScopeException ):
63109 pass
64110
65111
112+ @_legacy_error ("AssistantError" )
66113class 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" )
91139class RequestFailure (DashScopeException ):
92140 def __init__ (
93141 self ,
@@ -111,37 +159,46 @@ def __str__(self):
111159 return msg
112160
113161
162+ @_legacy_error ("UnknownMessageReceived" )
114163class UnknownMessageReceived (DashScopeException ):
115164 pass
116165
117166
167+ @_legacy_error ("InputDataRequired" )
118168class InputDataRequired (DashScopeException ):
119169 pass
120170
121171
172+ @_legacy_error ("InputRequired" )
122173class InputRequired (DashScopeException ):
123174 pass
124175
125176
177+ @_legacy_error ("UnsupportedDataType" )
126178class UnsupportedDataType (DashScopeException ):
127179 pass
128180
129181
182+ @_legacy_error ("ServiceUnavailableError" )
130183class ServiceUnavailableError (DashScopeException ):
131184 pass
132185
133186
187+ @_legacy_error ("UnsupportedHTTPMethod" )
134188class UnsupportedHTTPMethod (DashScopeException ):
135189 pass
136190
137191
192+ @_legacy_error ("AsyncTaskCreateFailed" )
138193class AsyncTaskCreateFailed (DashScopeException ):
139194 pass
140195
141196
197+ @_legacy_error ("UploadFileException" )
142198class UploadFileException (DashScopeException ):
143199 pass
144200
145201
202+ @_legacy_error ("TimeoutException" )
146203class TimeoutException (DashScopeException ):
147204 pass
0 commit comments