-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update codegen to generate base exception rather than UnknownServiceErrorException #484
Merged
+130
−20
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24e8ab9
Update codegen to generate base exception rather than UnknownServiceE…
kggilmer 034ea58
Remove UnknownServiceErrorException
kggilmer 3a03b77
Merge branch 'main' into fix-error-parse-exception
kggilmer 194596d
Merge branch 'main' into fix-error-parse-exception
kggilmer fefde45
Merge branch 'main' into fix-error-parse-exception
kggilmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
.../test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
package aws.sdk.kotlin.codegen.protocols.core | ||
|
||
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter | ||
import software.amazon.smithy.kotlin.codegen.model.expectShape | ||
import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver | ||
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator | ||
import software.amazon.smithy.kotlin.codegen.test.defaultSettings | ||
import software.amazon.smithy.kotlin.codegen.test.newTestContext | ||
import software.amazon.smithy.kotlin.codegen.test.shouldContainOnlyOnceWithDiff | ||
import software.amazon.smithy.kotlin.codegen.test.toSmithyModel | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.model.shapes.Shape | ||
import software.amazon.smithy.model.shapes.ShapeId | ||
import software.amazon.smithy.model.traits.TimestampFormatTrait | ||
import kotlin.test.Test | ||
|
||
class AwsHttpBindingProtocolGeneratorTest { | ||
|
||
@Test | ||
fun `it throws base service exception on error parse failure`() { | ||
val model = """ | ||
namespace com.test | ||
use aws.protocols#restJson1 | ||
|
||
@restJson1 | ||
service Example { | ||
version: "1.0.0", | ||
operations: [GetFoo] | ||
} | ||
|
||
operation GetFoo { | ||
errors: [FooError] | ||
} | ||
|
||
@error("server") | ||
structure FooError { | ||
payload: String | ||
} | ||
""".toSmithyModel() | ||
|
||
// This is the value that produces the name of the service base exception type | ||
val serviceSdkName = "SdkName" | ||
|
||
val testCtx = model.newTestContext( | ||
serviceName = "Example", | ||
settings = model.defaultSettings(sdkId = serviceSdkName) | ||
) | ||
val writer = KotlinWriter("com.test") | ||
val unit = TestableAwsHttpBindingProtocolGenerator() | ||
val op = model.expectShape<OperationShape>("com.test#GetFoo") | ||
|
||
unit.renderThrowOperationError(testCtx.generationCtx, op, writer) | ||
|
||
val actual = writer.toString() | ||
val expected = """ | ||
throw ${serviceSdkName}Exception("Failed to parse response as 'restJson1' error", ex).also { | ||
""".trimIndent() | ||
|
||
actual.shouldContainOnlyOnceWithDiff(expected) | ||
} | ||
|
||
// A concrete implementation of AwsHttpBindingProtocolGenerator to exercise renderThrowOperationError() | ||
class TestableAwsHttpBindingProtocolGenerator : AwsHttpBindingProtocolGenerator() { | ||
override fun renderDeserializeErrorDetails( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
op: OperationShape, | ||
writer: KotlinWriter | ||
) { | ||
// NOP | ||
} | ||
|
||
override val defaultTimestampFormat: TimestampFormatTrait.Format | ||
get() = TODO("Unneeded for test") | ||
|
||
override fun getProtocolHttpBindingResolver(model: Model, serviceShape: ServiceShape): HttpBindingResolver { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override fun renderSerializeOperationBody( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
op: OperationShape, | ||
writer: KotlinWriter | ||
) { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override fun renderDeserializeOperationBody( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
op: OperationShape, | ||
writer: KotlinWriter | ||
) { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override fun renderSerializeDocumentBody( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
shape: Shape, | ||
writer: KotlinWriter | ||
) { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override fun renderDeserializeDocumentBody( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
shape: Shape, | ||
writer: KotlinWriter | ||
) { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override fun renderDeserializeException( | ||
ctx: ProtocolGenerator.GenerationContext, | ||
shape: Shape, | ||
writer: KotlinWriter | ||
) { | ||
TODO("Unneeded for test") | ||
} | ||
|
||
override val protocol: ShapeId | ||
get() = TODO("Unneeded for test") | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment: I think we should reserve
TODO
for things that we honestly believe need to be done in the future. If we don't intend to implement unused interface members, I suggest using something with clearer semantics likefail
orthrow IllegalStateException
.