Skip to content

Commit

Permalink
Merge pull request #413 from aws/fix-struct-errorcode
Browse files Browse the repository at this point in the history
prevent nil pointer deref in ErrorCode() method of generated structs
  • Loading branch information
lucix-aws authored Feb 22, 2023
2 parents 4228229 + 2498bc7 commit 08fe458
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changelog/935d5acf9da941a2b1b8b326494e5c33.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "935d5acf-9da9-41a2-b1b8-b326494e5c33",
"type": "bugfix",
"description": "Prevent nil pointer dereference when accessing code in generated error structs.",
"modules": [
"."
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void renderErrorStructure() {
String errorCode = protocolGenerator == null ? shape.getId().getName(service)
: protocolGenerator.getErrorCode(service, shape);
writer.openBlock("func (e *$L) ErrorCode() string {", "}", structureSymbol.getName(), () -> {
writer.openBlock("if e.ErrorCodeOverride == nil {", "}", () -> {
writer.openBlock("if e == nil || e.ErrorCodeOverride == nil {", "}", () -> {
writer.write("return $S", errorCode);
});
writer.write("return *e.ErrorCodeOverride");
Expand Down

0 comments on commit 08fe458

Please sign in to comment.