[ 
https://issues.apache.org/jira/browse/SOLR-13022?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16936078#comment-16936078
 ] 

Hoss Man commented on SOLR-13022:
---------------------------------

at a glance the code generally seems correct ... although something seems off 
about the tests? 

In 2 places the test refers to 'prelim_sort' being invalid, but none of the 
requests being tested actually use prelim_sort ? 

And noticing that glitch in the test also draws my attention to the fact that 
the error message from validateSort() always starts with "Invalid sort..." but 
ideally we want to be able to say "Invalid sort option XXX for field foo" and 
"Invalid prelim_sort option YYY for  field bar".  Perhaps just change 
validateSort to validateSorts and take in the entire FacetField and check both 
of the two internally?

(another way to approach this might be to change the signature/impl of 
parseSort (or wrap it) to something so that you pass the sort param name to it 
and let it do the validation internally, something like...
{code:java}
private static FacetSort parseAndValidateSort(FacetRequest facet, Map 
facetArgs, String sortParam) {
  Object userSpecifiedSort = facetArgs.get(sortParam);
  FacetSort sort = parseSort(userSpecifiedSort); // existing parseSort method 
or logic like it inlined here
      // If we do inline it, we can also fix the existing error check...
      // "Expected string/map for 'sort', ..." to also use sortParam
  boolean isValid = // ...your new validation logic...
  if (! isValid) {
    throw new SolrException("Invalid " + sortparam + " for facet field " + ....
  }
  return sort;
} {code}
either way: could you please also make sure to include some simple javadocs on 
any new methods added (even if they are private)

> JSON Faceting NPE & 500 Error when attempting to sort on non-existent agg 
> (ie: typo)
> ------------------------------------------------------------------------------------
>
>                 Key: SOLR-13022
>                 URL: https://issues.apache.org/jira/browse/SOLR-13022
>             Project: Solr
>          Issue Type: Bug
>            Reporter: Hoss Man
>            Assignee: Hoss Man
>            Priority: Major
>         Attachments: SOLR-13022.patch
>
>
> JSON Faceting does not provide good error handling in the event of a typo / 
> non-existent agg stat name when sorting.  the parsing logic happily accepts 
> the bogus sortVariable w/o validation, and the subsequent execution logic 
> trows an NPE when it can't be found.
> Request...
> {noformat}
> curl http://localhost:8983/solr/techproducts/query -d 'rows=0&q=*:*&
> json.facet={
>   categories:{
>     type : terms,
>     field : cat,
>     sort : "xxxxx desc",
>   }
> }'
> {noformat}
> Response...
> {noformat}
> {
>   "responseHeader":{
>     "status":500,
>     "QTime":1,
>     "params":{
>       "q":"*:*",
>       "json.facet":"{\n  categories:{\n    type : terms,\n    field : cat,\n  
>   sort : \"xxxxx desc\",\n  }\n}",
>       "rows":"0"}},
>   "response":{"numFound":32,"start":0,"docs":[]
>   },
>   "error":{
>     "trace":"java.lang.NullPointerException\n\tat 
> org.apache.solr.search.facet.FacetFieldProcessor.lambda$findTopSlots$1(FacetFieldProcessor.java:287)
>     ...
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to