Skip to content

Commit

Permalink
Enrich local BEP upload errors with file path and digest possible.
Browse files Browse the repository at this point in the history
Closes #18461.

PiperOrigin-RevId: 534006853
Change-Id: I256297fe494393f13e178bf74f967b9b691db281
  • Loading branch information
benjaminp authored and copybara-github committed May 22, 2023
1 parent 354fd50 commit 997be1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private Single<List<PathMetadata>> queryRemoteCache(
return toSingle(() -> remoteCache.findMissingDigests(context, digestsToQuery), executor)
.onErrorResumeNext(
error -> {
reporterUploadError(error);
reportUploadError(error, null, null);
// Assuming all digests are missing if failed to query
return Single.just(ImmutableSet.copyOf(digestsToQuery));
})
Expand All @@ -267,13 +267,19 @@ private Single<List<PathMetadata>> queryRemoteCache(
});
}

private void reporterUploadError(Throwable error) {
private void reportUploadError(Throwable error, Path path, Digest digest) {
if (error instanceof CancellationException) {
return;
}

String errorMessage =
"Uploading BEP referenced local files: " + grpcAwareErrorMessage(error, verboseFailures);
String errorMessage = "Uploading BEP referenced local file";
if (path != null) {
errorMessage += " " + path;
}
if (digest != null) {
errorMessage += " " + digest;
}
errorMessage += ": " + grpcAwareErrorMessage(error, verboseFailures);

reporter.handle(Event.warn(errorMessage));
}
Expand All @@ -298,11 +304,11 @@ private Single<List<PathMetadata>> uploadLocalFiles(
path.isDirectory(),
// set remote to true so the PathConverter will use bytestream://
// scheme to convert the URI for this file
/*remote=*/ true,
/* remote= */ true,
path.isOmitted()))
.onErrorResumeNext(
error -> {
reporterUploadError(error);
reportUploadError(error, path.getPath(), path.getDigest());
return Single.just(path);
});
})
Expand All @@ -329,7 +335,7 @@ private Single<PathConverter> upload(Set<Path> files) {
try {
return readPathMetadata(file);
} catch (IOException e) {
reporterUploadError(e);
reportUploadError(e, file, null);
return new PathMetadata(
file,
/* digest= */ null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public void onCompleted() {

assertThat(eventHandler.getEvents()).isNotEmpty();
assertThat(eventHandler.getEvents().get(0).getMessage())
.contains("Uploading BEP referenced local files: ");
.contains("Uploading BEP referenced local file /file");

artifactUploader.release();

Expand Down

0 comments on commit 997be1e

Please sign in to comment.