Skip to content

Commit ea3ea29

Browse files
adwsinghrhernandez35
authored andcommitted
Fix message in generated exceptions when the message field has a different casing
1 parent fe3ffc3 commit ea3ea29

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

codegen/codegen-core/src/it/java/software/amazon/smithy/java/codegen/test/ExceptionsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.junit.jupiter.params.ParameterizedTest;
1919
import org.junit.jupiter.params.provider.MethodSource;
2020
import software.amazon.smithy.java.codegen.test.model.EmptyException;
21+
import software.amazon.smithy.java.codegen.test.model.ExceptionWithCapitalMessage;
2122
import software.amazon.smithy.java.codegen.test.model.ExceptionWithExtraStringException;
2223
import software.amazon.smithy.java.codegen.test.model.OptionalMessageException;
2324
import software.amazon.smithy.java.codegen.test.model.SimpleException;
@@ -90,6 +91,12 @@ void explicitDisableStackTraceCapture() {
9091
}
9192
}
9293

94+
@Test
95+
void testMessageMemberCapital() {
96+
var exception = ExceptionWithCapitalMessage.builder().message("OOOPS!").build();
97+
assertThat(exception.getMessage()).isEqualTo("OOOPS!");
98+
}
99+
93100
private static Throwable getCauseThrowable() {
94101
return new Throwable();
95102
}

codegen/codegen-core/src/it/resources/META-INF/smithy/exceptions/exception-tests.smithy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ operation Exceptions {
1414
SimpleException
1515
EmptyException
1616
OptionalMessageException
17+
ExceptionWithCapitalMessage
1718
]
1819
}
1920

@@ -25,6 +26,12 @@ structure ExceptionWithExtraStringException {
2526
extra: String
2627
}
2728

29+
@error("server")
30+
structure ExceptionWithCapitalMessage {
31+
@required
32+
Message: String
33+
}
34+
2835
@error("server")
2936
structure SimpleException {
3037
@required

codegen/codegen-core/src/main/java/software/amazon/smithy/java/codegen/generators/StructureGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ public void run() {
214214
// Here just in case we ever expand this trait.
215215
writer.putContext("errorFaultType", "OTHER");
216216
}
217-
if (shape.getMember("message").isPresent()) {
217+
boolean isMessagePresent = shape.getAllMembers()
218+
.values()
219+
.stream()
220+
.map(symbolProvider::toMemberName)
221+
.anyMatch("message"::equals);
222+
if (isMessagePresent) {
218223
writer.write(
219224
"super($$SCHEMA, builder.message, builder.$$cause, ${errorFault:T}.${errorFaultType:L}, builder.$$captureStackTrace, builder.$$deserialized);");
220225
} else {

0 commit comments

Comments
 (0)