Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST error readability #3303

Closed
missinglink opened this issue Jul 9, 2013 · 15 comments
Closed

REST error readability #3303

missinglink opened this issue Jul 9, 2013 · 15 comments
Assignees

Comments

@missinglink
Copy link
Contributor

Errors returned by the REST API are not easily human readable due to the way the data is stored in the error property.
Eg. https://gist.github.com/missinglink/e3cb9b127ae00e8c561c

You can 'prettify' the results, but it is still un-readable.
Eg. https://gist.github.com/pecke01/5956684

Note: (this specific error was caused by invalid syntax, the outer curly brackets were missing)

This issue makes it difficult for beginners to understand syntax errors and for advanced users to debug quickly when they make silly errors.

Ideally usage of ?pretty=1 would return "developer friendly" messages.

Any thoughts / suggestions? Maybe there is a tool which may help?

@damienalexandre
Copy link
Contributor

When I have this kind of error, I'm always opening my ElasticSearch logs. Errors are way more complete and usefull in there! Look at what I get for an undesirable , at the end of my query: https://gist.github.com/damienalexandre/5966477#file-gistfile1-txt-L38

I have the full stack trace, and the exception line 38:

org.elasticsearch.common.jackson.core.JsonParseException: Unexpected character ('}' (code 125)): was expecting either valid name character (for unquoted name) or double-quote (for quoted) to start field name

And my query is readable, as I sent it.

I agree that errors returned by the API could be improved 👍

@markharwood
Copy link
Contributor

I think the right long-term answer here (for query parse failures at least) is to change our query parsing logic so that when it encounters an error it can somehow annotate the point in the original JSON with the exact problem in the same way search highlighting shows where search terms are found in text or an IDE might highlight a compilation error.

This is clearly an ambitious goal so marking this issue as "high hanging fruit" in order to explore what can be done there.

@missinglink
Copy link
Contributor Author

In the case of json parser errors, I agree with @markharwood that ideally it would behave somewhat like the js parser in nodejs; which highlights the position the error occurred and facilitates rapid debugging.

/tmp/broken.js:5
var broken code here;
           ^^^^
SyntaxError: Unexpected identifier

This however is presentation logic which should not be the role of the API layer; however if it provided such granular information that allowed me to produce a view like the above then I'd be pretty happy.

The general issue is that the error messages don't appear to be machine readable nor human readable.

In the gist example above, the message I am scanning for is:
JsonParseException[Unexpected character (':' (code 58)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@16953ad9; line: 2, column: 13]]

The rest of the message is pretty much just noise and contains a bunch of characters which make machine parsing this section very difficult. Also any attempt to parse error messages in such a way would be very bad practise as they are bound to change over time.

Since we're talking json I think a familiar model for the errors could be one similar to the native javascript Error object and would look roughly something like this:

{
  "error": "I exist for backward compatibility",
  "status": 500,
  "message": "I am a human readable short description of the error",
  "class": "I am the Class of the error",
  "lineNumber": "I am very useful",
  "columnNumber": "as am I",
  "input": "I am the original input as related to the line and column numbers"
}

I guess the discussion should really be about how external errors are modelled, as they are currently not structured at all?

@missinglink
Copy link
Contributor Author

@polyfractal I saw you wrote a 'pretty error' parser for inquisitor, do you have any suggestions?

ref: https://github.com/polyfractal/elasticsearch-inquisitor#pretty-errors

@polyfractal
Copy link
Contributor

@missinglink Not much useful help, unfortunately. The parser in Inquisitor is very naive. It recognizes that ES exceptions tend to be large blocks of exceptions surrounded by brackets ([...]), with interior exceptions starting with nested:. It uses those two rules to split.

It's a good "80%" solution, but fails for a variety of exceptions that don't follow the same pattern. And it definitely doesn't produce machine-readable output, just something that humans can digest (since the most "interior" exception is usually the one you want, that's what Inquisitor shows as the main error)

@rashidkpc
Copy link

This is really important for Kibana as well, right now we have a rather difficult time informing the user what went wrong. +1 to the modeling it on the javascript error object. Error types/codes might be useful as well.

@zakmagnus
Copy link

What if the "parse error" is just that the query is too long? It might not be a good idea to parrot the entire thing back out to the caller. Also, note how silly it is that each of your shards gives you the same exact error. Constructing that string in memory (again, consider the case of an overlong query) might kill your node. If you OOM trying to build an error message, then you're going to receive a very unhelpful response.

Here is a thought: why is it necessary for the response to contain the request? Shouldn't the requester already know what its own request looks like? It seems reasonable to me that if the response is just "parse error starting at character ###, unexpected XYZ", then the requester can reasonably be expected to piece that together into a pretty display if it cares to.

@polyfractal
Copy link
Contributor

What if the "parse error" is just that the query is too long? It might not be a good idea to parrot the entire thing back out to the caller. Constructing that string in memory (again, consider the case of an overlong query) might kill your node. If you OOM trying to build an error message, then you're going to receive a very unhelpful response.

This generally isn't a problem, since ES places a limit on the size of the request body via the http.max_content_length setting (which defaults to 100mb).

So unless the limit has been set unreasonably high, or the search threadpool has been increased to allow an unreasonable number of queries to execute simultaneously, I think it is unlikely you would get an OOM in this particular part of the code.

Note: if the query would have caused an OOM when writing the parse error exception, it probably would have triggered an exception upstream in the networking stack first :)

Also, note how silly it is that each of your shards gives you the same exact error.

It's possible, although not common, for shards to return different errors (e.g. forgot to install a plugin on one node, different mappings if searching cross-index, corruption, etc).

Here is a thought: why is it necessary for the response to contain the request? Shouldn't the requester already know what its own request looks like? It seems reasonable to me that if the response is just "parse error starting at character ###, unexpected XYZ", then the requester can reasonably be expected to piece that together into a pretty display if it cares to.

I agree with your sentiment, but you'd be surprised (or disappointed) at how many production environments don't log their own queries. Many systems have no idea what's going through them and rely on the ES logs for retrospective analysis.

I think removing the queries from the exceptions would make them even more irritating, since many people don't log their own queries client-side.

@zakmagnus
Copy link

I have actually seen OOM's like this. The problem is not the raw amount of data, but rather the fact that it all gets concatenated together into one contiguous string. Also, again, each shard reports the same thing, with the original query embedded in it. So, it tries to build up a string of length roughly (number of shards) x (length of query). That can be much longer than any individual request is allowed to be.

I am indeed surprised to learn that many clients apparently don't know what query they're getting a response for. I didn't think about anything like that when I made my suggestion. Still, how about making it somehow configurable, whether the original request has to be part of an error message? The realistic set of clients should be supported, but I also think that reasonable clients should have a way to operate reasonably. If it's configurable, then everyone can have what they need.

@rashidkpc
Copy link

Any additional thoughts on the ?pretty method of returning developer/machine friendly errors? I'd love to at least get the name of the exceptions involved in an array. Ideally with key information points about each. But at least the names of the exceptions.

@rashidkpc
Copy link

poke

@szeitlin
Copy link

yeah, I second this request. I just got one of these errors.

@markharwood
Copy link
Contributor

@s1monw is keen to overhaul the parser framework and so this issue is likely to be addressed as part of that activity. Currently all data nodes parse the same JSON query and generally report the same parse issues. In Simon's proposal only the receiving node performs parsing/validation and for valid queries sends out non-JSON representations of the query to data nodes for execution. This is a big change and so improved error management will be addressed as part of that refactoring.

@s1monw
Copy link
Contributor

s1monw commented Apr 14, 2015

+1 to what @markharwood said. It's not helpful to add half baked solutions IMO we should get these exceptions when we parse the query and then we can render all the required things. Today we do that too late (on the executing node) and we are moving query parsing to the coordinating node (REST node) so we can throw the right exception and render more infos. I like to do these things right even if it takes much longer sorry for the delay.

@rashidkpc
Copy link

Important to consider this isn't limited to query parsing. This goes much deeper than the node that generates the error.

Simply moving validation to the coordinating node won't fix the premise of this ticket, which is that that REST errors are neither human nor machine readable. For example, invalid scripts will return a concatenated string leaving us with no way to tell the user what went wrong.

{
    "responses": [
        {
            "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.09][0]: SearchParseException[[logstash-2015.04.09][0]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@364f85f>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.10][0]: SearchParseException[[logstash-2015.04.10][0]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@222fa4da>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.11][0]: SearchParseException[[logstash-2015.04.11][0]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6c4d674c>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.12][0]: SearchParseException[[logstash-2015.04.12][0]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@4db8e620>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.13][0]: SearchParseException[[logstash-2015.04.13][0]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@2ecffeb5>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.13][1]: SearchParseException[[logstash-2015.04.13][1]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@4db8e620>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.14][1]: SearchParseException[[logstash-2015.04.14][1]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@595b3515>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.13][2]: SearchParseException[[logstash-2015.04.13][2]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6c4d674c>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.14][2]: SearchParseException[[logstash-2015.04.14][2]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@57f2c505>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.13][3]: SearchParseException[[logstash-2015.04.13][3]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@57f2c505>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.14][3]: SearchParseException[[logstash-2015.04.14][3]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@6ceec13a>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.13][4]: SearchParseException[[logstash-2015.04.13][4]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@65eff5be>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }{[Y0G3ct1dSgir04D--V8XEA][logstash-2015.04.14][4]: SearchParseException[[logstash-2015.04.14][4]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[-1],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@18841706>!]: Parse Failure [Failed to parse source [{\"size\":500,\"sort\":{\"@timestamp\":\"desc\"},\"query\":{\"filtered\":{\"query\":{\"query_string\":{\"analyze_wildcard\":true,\"query\":\"Squirrels*\"}},\"filter\":{\"bool\":{\"must\":[{\"range\":{\"@timestamp\":{\"gte\":1428649200000,\"lte\":1429426799999}}}],\"must_not\":[]}}}},\"highlight\":{\"pre_tags\":[\"@kibana-highlighted-field@\"],\"post_tags\":[\"@/kibana-highlighted-field@\"],\"fields\":{\"*\":{}}},\"aggs\":{\"2\":{\"date_histogram\":{\"field\":\"@timestamp\",\"interval\":\"3h\",\"pre_zone\":\"-07:00\",\"pre_zone_adjust_large_interval\":true,\"min_doc_count\":0,\"extended_bounds\":{\"min\":1428649200000,\"max\":1429426799999}}}},\"fields\":[\"*\",\"_source\"],\"script_fields\":{\"chunk\":{\"script\":\"deadbeef\",\"lang\":\"expression\"}},\"fielddata_fields\":[\"@timestamp\",\"utc_time\",\"relatedContent.article:modified_time\",\"relatedContent.article:published_time\"]}]]]; nested: ExpressionScriptCompilationException[Unknown variable [deadbeef] in expression]; }]"
        }
    ]
}

In this it would be great to get something like (could certainly be improved upon):

[{
 exception: "ExpressionScriptCompilationException",
 details: {
  type: "UnknownVar",
  variable: "deadbeef"
 }
}]

Or if a shard fails due to corruption, all we can tell the user is that the shard failed, we have no idea why, and neither do they.

"failures": [
                    {
                        "index": "logstash-2015.04.14",
                        "shard": 1,
                        "status": 500,
                        "reason": "QueryPhaseExecutionException[[logstash-2015.04.14][1]: query[filtered(_all:squirrels*)->BooleanFilter(+cache(@timestamp:[1428649200000 TO 1429426799999]))],from[0],size[500],sort[<custom:\"@timestamp\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@2b92372>!]: Query Failed [Failed to execute main query]]; nested: RuntimeException[java.io.IOException: read past EOF: NIOFSIndexInput(path=\"/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim\") off: 0 len: 1024 pos: 9943 chunkLen: 1024 end: 25880: NIOFSIndexInput(path=\"/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim\")]; nested: IOException[read past EOF: NIOFSIndexInput(path=\"/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim\") off: 0 len: 1024 pos: 9943 chunkLen: 1024 end: 25880: NIOFSIndexInput(path=\"/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim\")]; nested: EOFException[read past EOF: NIOFSIndexInput(path=\"/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim\") off: 0 len: 1024 pos: 9943 chunkLen: 1024 end: 25880]; "
                    }
                ]

Here I'd love to have:

[{
 exception: "EOFException",
 details: {
  type: "ReadPastEOF",
  path: "/Users/khanr/Projects/elasticsearch/data/beer/nodes/0/indices/logstash-2015.04.14/1/index/_a_Lucene41_0.tim",
  off: 0, 
  len: 1024, 
  pos: 9943, 
  chunkLen: 1024, 
  end: 25880
 }
}]

s1monw added a commit to s1monw/elasticsearch that referenced this issue Apr 17, 2015
This is a first cut aiming at progress rather than perfection for elastic#3303

It renders errors on the REST layer as JSON to allow more insight into the error message ie
the query with a missing index renders like this:

```
GET localhost:9200/foo1/_search/?q=~3&pretty=true
{
  "error" : {
    "type" : "index_missing_exception",
    "reason" : "[foo1] missing"
  },
  "status" : 404
}
```

or a search phase exception:

```
GET localhost:9200/_search?q=~3&pretty=true
{
  "error" : {
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "failed_shards" : [ {
      "shard" : 0,
      "index" : "foo",
      "node" : "0-75uocCQhyX4clLGbE6OQ",
      "reason" : {
        "type" : "search_parse_exception",
        "reason" : "Failed to parse source [{\"query\":{\"query_string\":{\"query\":\"~3\",\"lowercase_expanded_terms\":true,\"analyze_wildcard\":false}}}]",
        "caused_by" : {
          "type" : "query_parsing_exception",
          "reason" : "[foo] Failed to parse query [~3]",
          "caused_by" : {
            "type" : "parse_exception",
            "reason" : "Cannot parse '~3': Encountered \" <FUZZY_SLOP> \"~3 \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    ",
            "caused_by" : {
              "type" : "parse_exception",
              "reason" : "Encountered \" <FUZZY_SLOP> \"~3 \"\" at line 1, column 0.\nWas expecting one of:\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    <BAREOPER> ...\n    \"(\" ...\n    \"*\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    <REGEXPTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    <TERM> ...\n    \"*\" ...\n    "
            }
          }
        }
      }
    }]
  },
  "status" : 400
}
```
@s1monw s1monw closed this as completed in 15d58d9 Apr 24, 2015
markharwood added a commit that referenced this issue Apr 29, 2015
Extend SearchParseException and QueryParsingException to report position information in query JSON where errors were found. All query DSL parser classes that throw these exception types now pass the underlying position information (line and column number) at the point the error was found.

Closes #3303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants