Remove ExceptionHelper.detailedMessage#45878
Conversation
|
Pinging @elastic/es-core-infra |
|
I don't think changing these uses to |
| return "failed shard, shard " + routingEntry + ", message [" + message + "], failure [" + | ||
| ExceptionsHelper.detailedMessage(failure) + "], markAsStale [" + markAsStale + "]"; | ||
| return "failed shard, shard " + routingEntry + ", message [" + message + "], markAsStale [" + markAsStale + "], failure [" | ||
| + ExceptionsHelper.stackTrace(failure) + "]"; |
There was a problem hiding this comment.
I changed the order of fields here so that the stack trace comes last.
| components.add("markAsStale [" + markAsStale + "]"); | ||
| if (failure != null) { | ||
| components.add("failure [" + ExceptionsHelper.detailedMessage(failure) + "]"); | ||
| components.add("failure [" + ExceptionsHelper.stackTrace(failure) + "]"); |
There was a problem hiding this comment.
Also changed the order of elements here, so the stack trace is last.
rjernst
left a comment
There was a problem hiding this comment.
Thanks, this looks better to me. I left a couple last questions, and would also appreicate @jasontedor's opinion on whether using a full stack trace is always appropriate (IMO compared to the useless/reduced info from detailedmessage stacktrace is better).
| builder.append(' '); | ||
| } | ||
| return builder.append(ExceptionsHelper.detailedMessage(this).trim()).toString(); | ||
| return builder.append(super.toString().trim()).toString(); |
There was a problem hiding this comment.
Won't we lose all stack information by just using the exception tostring?
There was a problem hiding this comment.
Only if whatever's calling ElasticsearchException.toString() isn't also printing the stack trace. The problem with calling ElasticsearchException.stackTrace() here is that it calls .toString() on the exception, so you end up blowing the stack. detailedMessage() didn't do this because it essentially reimplemented Throwable.toString(). Open to ideas here.
There was a problem hiding this comment.
Ok, I see now why you are using toString(). I've fine with matching the behavior of Exception.
| return Strings.toString(builder); | ||
| } catch (Exception e) { | ||
| return "{ \"error\" : \"" + ExceptionsHelper.detailedMessage(e) + "\"}"; | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
Do we have a test for this failure case so we know the response is not already too far written to throw/serialize an exception like this?
There was a problem hiding this comment.
We do have integration tests in SearchSuggestIT with failure cases, but they don't look related to a failure to serialize content. I'd be happy to add a new test - any ideas how to provoke a failure when serialising a DirectCandidateGeneratorBuilder to XContent?
There was a problem hiding this comment.
I'm not exactly sure why we have this toString() implemented as json. But upon looking at this again, I think leaving the test coverage as is will be ok. Mimicking a failure would be quite difficult since the json builder is in memory and not mockable.
| assertThat(actualFailure.reason(), equalTo(expectedFailure.reason())); | ||
| // Serialising and deserialising an exception seems to remove the "java.base/" part from the stack trace, | ||
| // so these string replacements account for this. | ||
| assertThat(actualFailure.reason().replace("java.base/", ""), equalTo(expectedFailure.reason().replace("java.base/", ""))); |
There was a problem hiding this comment.
I made this change (and again in 1 other class) to get the test to pass, but I don't like it. I'd appreciate other suggestions.
…ptionhelper-detailedmessage
| @@ -368,7 +368,7 @@ private void internalRecoverFromStore(IndexShard indexShard) throws IndexShardRe | |||
| files = Arrays.toString(store.directory().listAll()); | |||
| } catch (Exception inner) { | |||
| inner.addSuppressed(e); | |||
There was a problem hiding this comment.
Seems odd that we are adding the original exception suppressed here. I dont' think it is necessary since the proper exception cause will be given in IndexShardRecoveryException below.
There was a problem hiding this comment.
Agreed, I've removed this line.
| // Serialising and deserialising an exception seems to remove the "java.base/" part from the stack trace, | ||
| // so these string replacements account for this. | ||
| assertThat( | ||
| actualFailure.reason().replace("java.base/", ""), |
There was a problem hiding this comment.
Can we check for a portion of the failure instead of an exact stack trace?
There was a problem hiding this comment.
Yes, I've reworked both instances of this.
A message in RestoreInProgressAllocationDecider included details about allocation decisions. If an allocation couldn't happen due to an exception, this resulted in a stack trace in the middle of the message. Move the details to the end of the message, which makes it easier to handle in tests.
Instead of relying on substring matching, parse the response JSON and check fields explicitly. This uses Jackson, which has been added to the build dependencies for :qa:smoke-test-http.
This required adding a getting to `VerificationFailure` so that the `cause` field could be accessed and added as suppressed exceptions elsewhere.
…ptionhelper-detailedmessage
|
@elasticsearch run elasticsearch-ci/1 |
…ptionhelper-detailedmessage
|
@rjernst I've merged in |
qa/smoke-test-http/build.gradle
Outdated
| apply plugin: 'elasticsearch.test-with-dependencies' | ||
|
|
||
| dependencies { | ||
| testCompile("com.fasterxml.jackson.core:jackson-databind:2.8.11") |
There was a problem hiding this comment.
nit: we normally do this without the parens so it maintains the "dsl" look
| client().prepareSearch().setQuery(builder).get(); | ||
| shardFailures = searchResponse.getShardFailures(); | ||
| assertThat("Expected shard failures, got none", shardFailures, not(emptyArray())); | ||
| } catch (SearchPhaseExecutionException e) { |
There was a problem hiding this comment.
we should use expectThrows here
There was a problem hiding this comment.
My understanding of this code is that it doesn't always throw an exception, so expectThrows isn't appropriate. It was largely taken from ElasticsearchAssertions#assertFailures(SearchRequestBuilder, RestStatus, Matcher<String>), which for $REASONS didn't work for this specific test with the exception helper changes.
There was a problem hiding this comment.
Sorry I misread the assert as a fail.
|
@elasticmachine test this please |
|
@elasticmachine run elasticsearch-ci/1 |
|
@elasticmachine run elasticsearch-ci/bwc |
1 similar comment
|
@elasticmachine run elasticsearch-ci/bwc |
|
@elasticmachine update branch |
|
@elasticmachine run elasticsearch-ci/2 |
Closes #19069.
I'm unsure of my approach here, so more opinions would be welcome. Mostly I replaced calls to
ExceptionHelper.detailedMessagewithe.getMessage(), which is all well and good but does remove some level of detail. There were a couple of cases where I replaced the method call with athrow, in the hope that code elsewhere will catch it and do the right thing.