Skip to content

Commit 4c4cdf8

Browse files
Use CallException for unknown errors
1 parent 625fa86 commit 4c4cdf8

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/CodegenUtils.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ public static Symbol getPluginSymbol(PythonSettings settings) {
8989
/**
9090
* Gets the service error symbol.
9191
*
92-
* <p>This error is the top-level error for the client. Errors surfaced by the client
93-
* MUST be a subclass of this or SmithyException so that customers can reliably catch
94-
* all the exceptions a client throws. The request pipeline will wrap exceptions of
95-
* other types.
92+
* <p>This error is the top-level error for modeled client errors.
9693
*
9794
* @param settings The client settings, used to account for module configuration.
9895
* @return Returns the symbol for the client's error class.

codegen/core/src/main/java/software/amazon/smithy/python/codegen/integrations/HttpProtocolGeneratorUtils.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,26 @@ public static void generateErrorDispatcher(
136136
var transportResponse = context.applicationProtocol().responseType();
137137
var delegator = context.writerDelegator();
138138
var errorDispatcher = context.protocolGenerator().getErrorDeserializationFunction(context, operation);
139-
var apiError = CodegenUtils.getServiceError(context.settings());
140139
var canReadResponseBody = canReadResponseBody(operation, context.model());
141140
delegator.useFileWriter(errorDispatcher.getDefinitionFile(), errorDispatcher.getNamespace(), writer -> {
142141
writer.pushState(new ErrorDispatcherSection(operation, errorShapeToCode, errorMessageCodeGenerator));
142+
writer.addImport("smithy_core.exceptions", "CallException");
143143
writer.write("""
144-
async def $1L(http_response: $2T, config: $3T) -> $4T:
145-
${5C|}
144+
async def $1L(http_response: $2T, config: $3T) -> CallException:
145+
${4C|}
146146
147147
match code.lower():
148-
${6C|}
148+
${5C|}
149149
150150
case _:
151-
return $4T(f"{code}: {message}")
151+
return CallException(
152+
message=f"{code}: {message}",
153+
fault="client" if http_response.status < 500 else "server"
154+
)
152155
""",
153156
errorDispatcher.getName(),
154157
transportResponse,
155158
configSymbol,
156-
apiError,
157159
writer.consumer(w -> errorMessageCodeGenerator.accept(context, w, canReadResponseBody)),
158160
writer.consumer(w -> errorCases(context, w, operation, errorShapeToCode)));
159161
writer.popState();

packages/smithy-core/src/smithy_core/exceptions.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class CallException(SmithyException, RetryInfo):
3535
"""Base exceptio to be used in application-level errors."""
3636

3737
fault: Literal["client", "server"] | None = None
38-
"""Whether the client or server is at fault."""
38+
"""Whether the client or server is at fault.
39+
40+
If None, then there was not enough information to determine fault.
41+
"""
3942

4043
message: str = field(default="", kw_only=False)
4144
"""The message of the error."""
@@ -46,10 +49,13 @@ def __post_init__(self):
4649

4750
@dataclass(kw_only=True)
4851
class ModeledException(CallException):
49-
"""Base excetpion to be used for modeled errors."""
52+
"""Base exception to be used for modeled errors."""
5053

5154
fault: Literal["client", "server"] | None = "client"
52-
"""Whether the client or server is at fault."""
55+
"""Whether the client or server is at fault.
56+
57+
If None, then there was not enough information to determine fault.
58+
"""
5359

5460

5561
class SerializationException(Exception):

0 commit comments

Comments
 (0)