From 7fd1af3bf660d888968d4ec5667cc6126c0ae6c1 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Tue, 9 Aug 2022 10:49:47 +0200 Subject: Improve messages on type mismatch --- .../java/com/yahoo/search/query/ranking/RankFeatures.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'container-search/src') 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)); } -- cgit v1.2.3