aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-08-09 10:49:47 +0200
committerJon Bratseth <bratseth@gmail.com>2022-08-09 10:49:47 +0200
commit7fd1af3bf660d888968d4ec5667cc6126c0ae6c1 (patch)
treec211d53641fe85dd56c02a11a63b4b79dc26e8be /container-search
parent8844e681bc04385bde449db144e3306529460265 (diff)
Improve messages on type mismatch
Diffstat (limited to 'container-search')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
index 5fed5f13c64..51be79f8c2e 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
@@ -75,7 +75,9 @@ public class RankFeatures implements Cloneable {
Object feature = features.get(name);
if (feature == null) return OptionalDouble.empty();
if (feature instanceof Double) return OptionalDouble.of((Double)feature);
- throw new IllegalArgumentException("Expected a double value of '" + name + "' but has " + feature);
+ throw new IllegalArgumentException("Expected '" + name + "' to be a double, but it is " +
+ (feature instanceof Tensor ? "the tensor " + ((Tensor)feature).toAbbreviatedString() :
+ "the string '" + feature + "'"));
}
/**
@@ -88,7 +90,7 @@ public class RankFeatures implements Cloneable {
if (feature == null) return Optional.empty();
if (feature instanceof Tensor) return Optional.of((Tensor)feature);
if (feature instanceof Double) return Optional.of(Tensor.from((Double)feature));
- throw new IllegalArgumentException("Expected a tensor value of '" + name + "' but has " + feature);
+ throw new IllegalArgumentException("Expected '" + name + "' to be a tensor, but it is the string '" + feature + "'");
}
/**
@@ -100,9 +102,9 @@ public class RankFeatures implements Cloneable {
Object feature = features.get(name);
if (feature == null) return Optional.empty();
if (feature instanceof String) return Optional.of((String)feature);
- // TODO: Use toShortString for tensors below
- throw new IllegalArgumentException("Expected a string value of '" + name + "' but has " +
- (feature instanceof Tensor ? ((Tensor)feature).toString() : feature));
+ throw new IllegalArgumentException("Expected '" + name + "' to be a string, but it is " +
+ (feature instanceof Tensor ? "the tensor " + ((Tensor)feature).toAbbreviatedString() :
+ "the double " + feature));
}