diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 7616c83e52..a709eb5d39 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -487,13 +487,15 @@ open class ServerCodegenVisitor( } if (shape.isEventStream()) { - rustCrate.withModule(RustModule.Error) { - val symbol = codegenContext.symbolProvider.toSymbol(shape) - val errors = shape.eventStreamErrors() - .map { model.expectShape(it.asMemberShape().get().target, StructureShape::class.java) } - val errorSymbol = shape.eventStreamErrorSymbol(codegenContext.symbolProvider) - ServerOperationErrorGenerator(model, codegenContext.symbolProvider, symbol, errors) - .renderErrors(this, errorSymbol, symbol) + val errors = shape.eventStreamErrors() + .map { model.expectShape(it.asMemberShape().get().target, StructureShape::class.java) } + if (errors.isNotEmpty()) { + rustCrate.withModule(RustModule.Error) { + val symbol = codegenContext.symbolProvider.toSymbol(shape) + val errorSymbol = shape.eventStreamErrorSymbol(codegenContext.symbolProvider) + ServerOperationErrorGenerator(model, codegenContext.symbolProvider, symbol, errors) + .renderErrors(this, errorSymbol, symbol) + } } } }