Apache Solr open-source search software
SOLR-8598: better error message for unknown facet type
yonik85ae198033d8
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRequest.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRequest.javaindex bb8302c2cc9..33ce5dcfb41 100644--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRequest.java+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRequest.java@@ -162,7 +162,7 @@ abstract class FacetParser<FacetRequestT extends FacetRequest> {}protected RuntimeException err(String msg) {- return new SolrException(SolrException.ErrorCode.BAD_REQUEST, msg + " ,path="+getPathStr());+ return new SolrException(SolrException.ErrorCode.BAD_REQUEST, msg + " , path="+getPathStr());}public abstract FacetRequest parse(Object o) throws SyntaxError;@@ -192,7 +192,7 @@ abstract class FacetParser<FacetRequestT extends FacetRequest> {} else if (parsedValue instanceof AggValueSource) {facet.addStat(key, (AggValueSource)parsedValue);} else {- throw new RuntimeException("Huh? TODO: " + parsedValue);+ throw err("Unknown facet type key=" + key + " class=" + (parsedValue == null ? "null" : parsedValue.getClass().getName()));}}} else {@@ -248,7 +248,11 @@ abstract class FacetParser<FacetRequestT extends FacetRequest> {return parseRangeFacet(key, args);}- return parseStat(key, type, args);+ AggValueSource stat = parseStat(key, type, args);+ if (stat == null) {+ throw err("Unknown facet or stat. key=" + key + " type=" + type + " args=" + args);+ }+ return stat;}diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.javaindex fff834b3992..45c9845c845 100644--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonFacets.java@@ -28,8 +28,8 @@ import java.util.Map;import java.util.Random;import com.tdunning.math.stats.AVLTreeDigest;+import org.apache.solr.common.SolrException;import org.apache.solr.util.hll.HLL;-import org.apache.lucene.queryparser.flexible.standard.processors.NumericQueryNodeProcessor;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.packed.GrowableWriter;import org.apache.lucene.util.packed.PackedInts;@@ -1258,6 +1258,26 @@ public class TestJsonFacets extends SolrTestCaseHS {}+ @Test+ public void testErrors() throws Exception {+ doTestErrors(Client.localClient());+ }++ public void doTestErrors(Client client) throws Exception {+ ModifiableSolrParams p = params("rows", "0");+ client.deleteByQuery("*:*", null);++ try {+ client.testJQ(params("ignore_exception", "true", "q", "*:*"+ , "json.facet", "{f:{type:ignore_exception_aaa, field:bbbbbb}}"+ )+ );+ } catch (SolrException e) {+ assertTrue( e.getMessage().contains("ignore_exception_aaa") );+ }++ }+public void XtestPercentiles() {