aboutsummaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2024-05-21 12:02:46 +0200
committerjonmv <venstad@gmail.com>2024-05-21 12:02:46 +0200
commit1f4f75e37530af70fc3e87839d2ab698fa1eba07 (patch)
tree460d593e0c191965e835cebfe417da0c14da3daf /vespaclient-container-plugin
parent2b08f380d52c7c5b5e5678f5f582fb93647c2529 (diff)
Improve error message when visiting with wrong document type
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java4
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java10
2 files changed, 12 insertions, 2 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java
index 6e07661235e..4bd78d2030f 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/resource/DocumentV1ApiHandler.java
@@ -1621,8 +1621,8 @@ public class DocumentV1ApiHandler extends AbstractRequestHandler {
static String resolveBucket(StorageCluster cluster, Optional<String> documentType,
List<String> bucketSpaces, Optional<String> bucketSpace) {
return documentType.map(type -> cluster.bucketOf(type)
- .orElseThrow(() -> new IllegalArgumentException("Document type '" + type + "' in cluster '" + cluster.name() +
- "' is not mapped to a known bucket space")))
+ .orElseThrow(() -> new IllegalArgumentException("There is no document type '" + type + "' in cluster '" + cluster.name() +
+ "', only '" + String.join("', '", cluster.documentBuckets.keySet()) + "'")))
.or(() -> bucketSpace.map(space -> {
if ( ! bucketSpaces.contains(space))
throw new IllegalArgumentException("Bucket space '" + space + "' is not a known bucket space; expected one of " +
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java
index b2c0b1b2ce8..2d3198cc7f4 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/resource/DocumentV1ApiTest.java
@@ -185,8 +185,18 @@ public class DocumentV1ApiTest {
StorageCluster cluster = DocumentV1ApiHandler.resolveCluster(Optional.of("content"), clusters);
assertEquals(FixedBucketSpaces.defaultSpace(),
DocumentV1ApiHandler.resolveBucket(cluster, Optional.of("music"), List.of(), Optional.empty()));
+ assertEquals(FixedBucketSpaces.defaultSpace(),
+ DocumentV1ApiHandler.resolveBucket(cluster, Optional.empty(), List.of(), Optional.empty()));
assertEquals(FixedBucketSpaces.globalSpace(),
DocumentV1ApiHandler.resolveBucket(cluster, Optional.empty(), List.of(FixedBucketSpaces.globalSpace()), Optional.of("global")));
+ try {
+ DocumentV1ApiHandler.resolveBucket(cluster, Optional.of("musicc"), List.of(), Optional.empty());
+ fail("should fail with unknown document type");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("There is no document type 'musicc' in cluster 'content', only 'music'",
+ e.getMessage());
+ }
}
@Test