From the following code:
|
public List<SnapshotInfo> getSnapshots(String repo) { |
|
List<SnapshotInfo> snapshots = successfulResponses.get(repo); |
|
if (snapshots != null) { |
|
return snapshots; |
|
} |
|
ElasticsearchException error = failedResponses.get(repo); |
|
if (error == null) { |
|
throw new IllegalArgumentException("No such repository"); |
|
} |
|
throw error; |
|
} |
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.
From the following code:
elasticsearch/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java
Lines 156 to 166 in f879e84
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:
Now fails.
The exception is generated from the
snaps.getSnapshots(repo)call above, however, the stacktrace for the exception actually traces back to the linewhich is very confusing, because that line itself is wrapped in a try/catch.
GetSnapshotsResponseshould change this line:elasticsearch/server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java
Line 165 in f879e84
Into something like
So that the stacktrace correctly identifies the caller.