Skip to content

Commit 1791623

Browse files
committed
Document error_trace
The `error_trace` parameter turns on the `stack_trace` field in errors which returns stack traces. Removes documentation for `camelCase` because it hasn't worked in a while.... Documents the internal parameters used to render stack traces as internal only. Closes #21708
1 parent c7b70fc commit 1791623

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed

core/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
5252
public static final Version V_5_1_0_UNRELEASED = Version.fromId(5010099);
5353
public static final Version V_5_0_2_UNRELEASED = Version.fromId(5000299);
5454
public static final Version UNKNOWN_VERSION_ADDED = Version.fromId(0);
55+
/**
56+
* Passed in the {@link Params} of {@link #toXContent(XContentBuilder, org.elasticsearch.common.xcontent.ToXContent.Params, Throwable)}
57+
* to control if the {@code caused_by} element should render. Unlike most parameters to {@code toXContent} methods this parameter is
58+
* internal only and not available as a URL parameter.
59+
*/
5560
public static final String REST_EXCEPTION_SKIP_CAUSE = "rest.exception.cause.skip";
61+
/**
62+
* Passed in the {@link Params} of {@link #toXContent(XContentBuilder, org.elasticsearch.common.xcontent.ToXContent.Params, Throwable)}
63+
* to control if the {@code stack_trace} element should render. Unlike most parameters to {@code toXContent} methods this parameter is
64+
* internal only and not available as a URL parameter. Use the {@code error_trace} parameter instead.
65+
*/
5666
public static final String REST_EXCEPTION_SKIP_STACK_TRACE = "rest.exception.stacktrace.skip";
5767
public static final boolean REST_EXCEPTION_SKIP_STACK_TRACE_DEFAULT = true;
5868
public static final boolean REST_EXCEPTION_SKIP_CAUSE_DEFAULT = false;
@@ -308,7 +318,7 @@ private void xContentHeader(XContentBuilder builder, String key, List<String> va
308318
}
309319

310320
/**
311-
* Statis toXContent helper method that also renders non {@link org.elasticsearch.ElasticsearchException} instances as XContent.
321+
* Static toXContent helper method that also renders non {@link org.elasticsearch.ElasticsearchException} instances as XContent.
312322
*/
313323
public static void toXContent(XContentBuilder builder, Params params, Throwable ex) throws IOException {
314324
ex = ExceptionsHelper.unwrapCause(ex);

docs/reference/api-conventions.asciidoc

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,12 +586,82 @@ generates an edit distance based on the length of the term. For lengths:
586586
--
587587

588588
[float]
589-
=== Result Casing
589+
[[common-options-error-options]]
590+
=== Enabling stack traces
590591

591-
All REST APIs accept the `case` parameter. When set to `camelCase`, all
592-
field names in the result will be returned in camel casing, otherwise,
593-
underscore casing will be used. Note, this does not apply to the source
594-
document indexed.
592+
By default when a request returns an error Elasticsearch doesn't include the
593+
stack trace of the error. You can enable that behavior by setting the
594+
`error_trace` url parameter to `true`. For example, by default when you send an
595+
invalid `size` parameter to the `_search` API:
596+
597+
[source,js]
598+
----------------------------------------------------------------------
599+
POST /twitter/_search?size=surprise_me
600+
----------------------------------------------------------------------
601+
// CONSOLE
602+
// TEST[catch:request]
603+
604+
The response looks like:
605+
606+
[source,js]
607+
----------------------------------------------------------------------
608+
{
609+
"error" : {
610+
"root_cause" : [
611+
{
612+
"type" : "illegal_argument_exception",
613+
"reason" : "Failed to parse int parameter [size] with value [surprise_me]"
614+
}
615+
],
616+
"type" : "illegal_argument_exception",
617+
"reason" : "Failed to parse int parameter [size] with value [surprise_me]",
618+
"caused_by" : {
619+
"type" : "number_format_exception",
620+
"reason" : "For input string: \"surprise_me\""
621+
}
622+
},
623+
"status" : 400
624+
}
625+
----------------------------------------------------------------------
626+
// TESTRESPONSE
627+
628+
But if you set `error_trace=true`:
629+
630+
[source,js]
631+
----------------------------------------------------------------------
632+
POST /twitter/_search?size=surprise_me&error_trace=true
633+
----------------------------------------------------------------------
634+
// CONSOLE
635+
// TEST[catch:request]
636+
637+
The response looks like:
638+
639+
[source,js]
640+
----------------------------------------------------------------------
641+
{
642+
"error": {
643+
"root_cause": [
644+
{
645+
"type": "illegal_argument_exception",
646+
"reason": "Failed to parse int parameter [size] with value [surprise_me]",
647+
"stack_trace": "Failed to parse int parameter [size] with value [surprise_me]]; nested: IllegalArgumentException..."
648+
}
649+
],
650+
"type": "illegal_argument_exception",
651+
"reason": "Failed to parse int parameter [size] with value [surprise_me]",
652+
"stack_trace": "java.lang.IllegalArgumentException: Failed to parse int parameter [size] with value [surprise_me]\n at org.elasticsearch.rest.RestRequest.paramAsInt(RestRequest.java:175)...",
653+
"caused_by": {
654+
"type": "number_format_exception",
655+
"reason": "For input string: \"surprise_me\"",
656+
"stack_trace": "java.lang.NumberFormatException: For input string: \"surprise_me\"\n at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)..."
657+
}
658+
},
659+
"status": 400
660+
}
661+
----------------------------------------------------------------------
662+
// TESTRESPONSE[s/"stack_trace": "Failed to parse int parameter.+\.\.\."/"stack_trace": $body.error.root_cause.0.stack_trace/]
663+
// TESTRESPONSE[s/"stack_trace": "java.lang.IllegalArgum.+\.\.\."/"stack_trace": $body.error.stack_trace/]
664+
// TESTRESPONSE[s/"stack_trace": "java.lang.Number.+\.\.\."/"stack_trace": $body.error.caused_by.stack_trace/]
595665

596666
[float]
597667
=== Request body in query string

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/section/MatchAssertion.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ private void compare(String field, @Nullable Object actual, Object expected) {
173173
return;
174174
}
175175
if (Objects.equals(expected, actual)) {
176+
if (expected instanceof String) {
177+
String expectedString = (String) expected;
178+
if (expectedString.length() > 50) {
179+
expectedString = expectedString.substring(0, 50) + "...";
180+
}
181+
field(field, "same [" + expectedString + "]");
182+
return;
183+
}
176184
field(field, "same [" + expected + "]");
177185
return;
178186
}

0 commit comments

Comments
 (0)