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
…18481)

Closes #18461.

PiperOrigin-RevId: 534006853
Change-Id: I256297fe494393f13e178bf74f967b9b691db281

Co-authored-by: Benjamin Peterson <benjamin@engflow.com>
  • Loading branch information
iancha1992 and benjaminp authored May 24, 2023
1 parent c422565 commit 53d785b
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 @@ -333,7 +333,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 53d785b

Please sign in to comment.