Skip to content

Commit 3444966

Browse files
authored
Add clear error msg if operation not known (#5995)
Throw a clear error message if we construct a paginator spec for an operation that is not modeled in the service model.
1 parent 278563e commit 3444966

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/PaginatorsClassSpec.java

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public PaginatorsClassSpec(IntermediateModel model, String c2jOperationName, Pag
6363
this.poetExtensions = new PoetExtension(model);
6464
this.typeProvider = new TypeProvider(model);
6565
this.operationModel = model.getOperation(c2jOperationName);
66+
if (operationModel == null) {
67+
throw new IllegalArgumentException("The service model does not model an operation '" + c2jOperationName + "'");
68+
}
6669
this.paginationDocs = new PaginationDocs(model, operationModel, paginatorDefinition);
6770
}
6871

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.poet.paginators;
17+
18+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
19+
20+
import com.squareup.javapoet.ClassName;
21+
import com.squareup.javapoet.TypeSpec;
22+
import org.junit.jupiter.api.Test;
23+
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
24+
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
25+
import software.amazon.awssdk.codegen.poet.ClientTestModels;
26+
27+
public class PaginatorsClassSpecTest {
28+
@Test
29+
public void constructor_unknownOperationName_throws() {
30+
assertThatThrownBy(() -> new TestPaginatorSpec(ClientTestModels.awsJsonServiceModels(),
31+
"~~DoesNotExist",
32+
new PaginatorDefinition()))
33+
.isInstanceOf(IllegalArgumentException.class)
34+
.hasMessageContaining("The service model does not model an operation '~~DoesNotExist'");
35+
}
36+
37+
private static class TestPaginatorSpec extends PaginatorsClassSpec {
38+
TestPaginatorSpec(IntermediateModel model, String c2jOperationName, PaginatorDefinition paginatorDefinition) {
39+
super(model, c2jOperationName, paginatorDefinition);
40+
}
41+
42+
@Override
43+
public TypeSpec poetSpec() {
44+
throw new UnsupportedOperationException();
45+
}
46+
47+
@Override
48+
public ClassName className() {
49+
throw new UnsupportedOperationException();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)