From e83e9b3e93b7f02fbc28e59b2fe23592931eda0c Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Tue, 11 Jan 2022 10:30:14 -0800 Subject: [PATCH] chore: remove filterSensitiveLog for service exceptions (#488) --- .../amazon/smithy/typescript/codegen/StructureGenerator.java | 5 ----- .../smithy/typescript/codegen/StructuredMemberWriter.java | 4 ++++ .../smithy/typescript/codegen/StructureGeneratorTest.java | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java index efdfff70fa9..d4b45120961 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructureGenerator.java @@ -168,10 +168,6 @@ private void renderNonErrorStructure() { * $fault: "client"; * resourceType: string | undefined; * } - * - * export namespace NoSuchResource { - * export const filterSensitiveLog = (obj: NoSuchResource): any => ({...obj}); - * } * } */ private void renderErrorStructure() { @@ -197,7 +193,6 @@ private void renderErrorStructure() { structuredMemberWriter.writeMembers(writer, shape); writer.closeBlock("}"); // interface writer.write(""); - renderStructureNamespace(structuredMemberWriter, false); } private void renderStructureNamespace(StructuredMemberWriter structuredMemberWriter, boolean includeValidation) { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java index 74676f12288..ab72e770ff9 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/StructuredMemberWriter.java @@ -34,6 +34,7 @@ import software.amazon.smithy.model.shapes.StringShape; import software.amazon.smithy.model.shapes.StructureShape; import software.amazon.smithy.model.traits.EnumTrait; +import software.amazon.smithy.model.traits.ErrorTrait; import software.amazon.smithy.model.traits.IdempotencyTokenTrait; import software.amazon.smithy.model.traits.LengthTrait; import software.amazon.smithy.model.traits.MediaTypeTrait; @@ -163,6 +164,9 @@ private void writeStructureFilterSensitiveLog( } else if (structureTarget.hasTrait(StreamingTrait.class) && structureTarget.isUnionShape()) { // disable logging for StreamingTrait writer.write("'STREAMING_CONTENT'"); + } else if (structureTarget.hasTrait(ErrorTrait.class)) { + // Sensitive logs are not filtered from errors. + writer.write("$L", structureParam); } else { // Call filterSensitiveLog on Structure. writer.write("$T.filterSensitiveLog($L)", symbolProvider.toSymbol(structureTarget), structureParam); diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java index e0b07e138d2..6fa58946994 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java @@ -481,7 +481,6 @@ private void testErrorStructureCodegen(String file, String expectedType) { String contents = testStructureCodegen(file, expectedType); assertThat(contents, containsString("as __SmithyException")); - assertThat(contents, containsString("namespace Err {")); } @Test