Skip to content

Commit ec0c802

Browse files
authored
Match CBOR errors via shape name instead of shapeId (#587)
1 parent 0c16dbb commit ec0c802

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

codegen/smithy-go-codegen/src/main/java/software/amazon/smithy/go/codegen/protocol/rpc2/cbor/Rpc2CborProtocolGenerator.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@ private GoWriter.Writable deserializeOperationError(
136136
}
137137
138138
_ = v
139-
switch string(typ) {
139+
// namespace can be mangled by service, so matching by error shape name
140+
errorParts := strings.Split(typ, "#")
141+
errorName := errorParts[len(errorParts)-1]
142+
switch string(errorName) {
140143
$errors:W
141144
default:
142145
$awsQueryCompatible:W
@@ -170,7 +173,7 @@ private GoWriter.Writable deserializeOperationError(
170173

171174
private GoWriter.Writable deserializeErrorCase(GenerationContext ctx, StructureShape error) {
172175
return goTemplate("""
173-
case $type:S:
176+
case $errorType:S:
174177
verr, err := $deserialize:L(v)
175178
if err != nil {
176179
return &$deserError:T{
@@ -182,6 +185,7 @@ private GoWriter.Writable deserializeErrorCase(GenerationContext ctx, StructureS
182185
return verr
183186
""",
184187
MapUtils.of(
188+
"errorType", error.getId().getName(),
185189
"deserError", SmithyGoDependency.SMITHY.pointableSymbol("DeserializationError"),
186190
"deserialize", getDeserializerName(error),
187191
"equalFold", SmithyGoDependency.STRINGS.func("EqualFold"),
@@ -193,6 +197,10 @@ private GoWriter.Writable deserializeErrorCase(GenerationContext ctx, StructureS
193197
));
194198
}
195199

200+
private String getShapeName(ShapeId id) {
201+
return id.getName() + "Error";
202+
}
203+
196204
private GoWriter.Writable deserializeAwsQueryError() {
197205
return goTemplate("""
198206
if qtype := getAwsQueryErrorCode(resp); len(qtype) > 0 {

0 commit comments

Comments
 (0)