Closed
Description
From the following code:
It's possible for snapshot exceptions to be generated on a different line than where they are actually thrown, for example, code that prior to #42090 worked like this:
GetSnapshotsRequest getSnapshotsRequest = new GetSnapshotsRequest(new String[]{repo}, new String[]{snapshotName});
final GetSnapshotsResponse snaps;
try {
snaps = client.snapshot().get(getSnapshotsRequest, RequestOptions.DEFAULT);
} catch (Exception e) {
if (e.getMessage().contains("snapshot_missing_exception")) {
fail("snapshot does not exist: " + snapshotName);
}
throw e;
}
Optional<SnapshotInfo> info = snaps.getSnapshots(repo).stream().findFirst();
if (info.isPresent()) {
info.ifPresent(si -> {
assertThat(si.snapshotId().getName(), equalTo(snapshotName));
assertThat(si.state(), equalTo(SnapshotState.SUCCESS));
});
} else {
fail("unable to find snapshot; " + snapshotName);
}
Now fails.
The exception is generated from the snaps.getSnapshots(repo)
call above, however, the stacktrace for the exception actually traces back to the line
snaps = client.snapshot().get(getSnapshotsRequest, RequestOptions.DEFAULT);
which is very confusing, because that line itself is wrapped in a try/catch.
GetSnapshotsResponse
should change this line:
Into something like
throw new ElasticsearchException(error);
So that the stacktrace correctly identifies the caller.