Skip to content

Commit

Permalink
feat: Improve exception thrown on failure to upload/download
Browse files Browse the repository at this point in the history
This should make #8552 much easier to diagnose.
  • Loading branch information
jskeet committed Feb 20, 2023
1 parent 8579df7 commit 4782e03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ private RequestBuilder CreateRequestBuilder(Object source)
progress.Report(InitialDownloadProgress.Instance);
}
var result = downloader.Download(uri, destination);
if (result.Status == DownloadStatus.Failed)
{
throw result.Exception;
}
result.ThrowOnFailure();
// This will have been populated by the downloader.
return metadata;
}
Expand All @@ -160,10 +157,7 @@ private RequestBuilder CreateRequestBuilder(Object source)
progress.Report(InitialDownloadProgress.Instance);
}
var result = await downloader.DownloadAsync(uri, destination, cancellationToken).ConfigureAwait(false);
if (result.Status == DownloadStatus.Failed)
{
throw result.Exception;
}
result.ThrowOnFailure();
// This will have been populated by the downloader.
return metadata;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Google.Api.Gax;
using Google.Apis.Storage.v1;
using Google.Apis.Upload;
using Google.Cloud.Storage.V1;
using System;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -149,7 +148,7 @@ private sealed class UploadHelper
internal Object Execute()
{
_mediaUpload.Upload();
CheckFinalProgress();
_mediaUpload.GetProgress().ThrowOnFailure();
var result = _mediaUpload.ResponseBody;
var hash = _crc == null ? result.Crc32c : Convert.ToBase64String(_crc.GetHash());
if (hash != result.Crc32c)
Expand All @@ -171,7 +170,7 @@ internal Object Execute()
internal async Task<Object> ExecuteAsync(CancellationToken cancellationToken)
{
await _mediaUpload.UploadAsync(cancellationToken).ConfigureAwait(false);
CheckFinalProgress();
_mediaUpload.GetProgress().ThrowOnFailure();
var result = _mediaUpload.ResponseBody;
var hash = _crc == null ? result.Crc32c : Convert.ToBase64String(_crc.GetHash());
if (hash != result.Crc32c)
Expand All @@ -192,15 +191,6 @@ internal async Task<Object> ExecuteAsync(CancellationToken cancellationToken)
}
return result;
}

private void CheckFinalProgress()
{
var finalProgress = _mediaUpload.GetProgress();
if (finalProgress.Exception != null)
{
throw finalProgress.Exception;
}
}
}
}
}

0 comments on commit 4782e03

Please sign in to comment.