diff options
| author | Petter Rasmussen | 2016-04-09 18:28:04 +0200 |
|---|---|---|
| committer | Petter Rasmussen | 2016-04-09 18:37:38 +0200 |
| commit | 28c5b9beb7b16dc0e1a39fc61163868dcbc02d19 (patch) | |
| tree | 79dcc943d8d1dedab6f5fed180f42dadca23020f | |
| parent | 0e1057e475525536dce2db4754e9d9840ab086f2 (diff) | |
| download | gdrive-28c5b9beb7b16dc0e1a39fc61163868dcbc02d19.tar.bz2 | |
Give proper timeout error message
| -rw-r--r-- | drive/download.go | 3 | ||||
| -rw-r--r-- | drive/errors.go | 5 | ||||
| -rw-r--r-- | drive/revision_download.go | 3 | ||||
| -rw-r--r-- | drive/sync_download.go | 2 | ||||
| -rw-r--r-- | drive/sync_upload.go | 4 | ||||
| -rw-r--r-- | drive/update.go | 3 | ||||
| -rw-r--r-- | drive/upload.go | 6 |
7 files changed, 26 insertions, 0 deletions
diff --git a/drive/download.go b/drive/download.go index 3cb8310..ec1af8a 100644 --- a/drive/download.go +++ b/drive/download.go @@ -125,6 +125,9 @@ func (self *Drive) downloadBinary(f *drive.File, args DownloadArgs) (int64, int6 res, err := self.service.Files.Get(f.Id).Context(ctx).Download() if err != nil { + if isTimeoutError(err) { + return 0, 0, fmt.Errorf("Failed to download file: timeout, no data was transferred for %v", args.Timeout) + } return 0, 0, fmt.Errorf("Failed to download file: %s", err) } diff --git a/drive/errors.go b/drive/errors.go index e7631f7..465d818 100644 --- a/drive/errors.go +++ b/drive/errors.go @@ -1,6 +1,7 @@ package drive import ( + "golang.org/x/net/context" "google.golang.org/api/googleapi" "time" ) @@ -16,6 +17,10 @@ func isBackendError(err error) bool { return ok && ae.Code >= 500 && ae.Code <= 599 } +func isTimeoutError(err error) bool { + return err == context.Canceled +} + func exponentialBackoffSleep(try int) { seconds := pow(2, try) time.Sleep(time.Duration(seconds) * time.Second) diff --git a/drive/revision_download.go b/drive/revision_download.go index 57392a5..6bed886 100644 --- a/drive/revision_download.go +++ b/drive/revision_download.go @@ -36,6 +36,9 @@ func (self *Drive) DownloadRevision(args DownloadRevisionArgs) (err error) { res, err := getRev.Context(ctx).Download() if err != nil { + if isTimeoutError(err) { + return fmt.Errorf("Failed to download file: timeout, no data was transferred for %v", args.Timeout) + } return fmt.Errorf("Failed to download file: %s", err) } diff --git a/drive/sync_download.go b/drive/sync_download.go index 2494557..10dfd16 100644 --- a/drive/sync_download.go +++ b/drive/sync_download.go @@ -197,6 +197,8 @@ func (self *Drive) downloadRemoteFile(id, fpath string, args DownloadSyncArgs, t exponentialBackoffSleep(try) try++ return self.downloadRemoteFile(id, fpath, args, try) + } else if isTimeoutError(err) { + return fmt.Errorf("Failed to download file: timeout, no data was transferred for %v", args.Timeout) } else { return fmt.Errorf("Failed to download file: %s", err) } diff --git a/drive/sync_upload.go b/drive/sync_upload.go index c509c0a..bb1ab33 100644 --- a/drive/sync_upload.go +++ b/drive/sync_upload.go @@ -317,6 +317,8 @@ func (self *Drive) uploadMissingFile(parentId string, lf *LocalFile, args Upload exponentialBackoffSleep(try) try++ return self.uploadMissingFile(parentId, lf, args, try) + } else if isTimeoutError(err) { + return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout) } else { return fmt.Errorf("Failed to upload file: %s", err) } @@ -356,6 +358,8 @@ func (self *Drive) updateChangedFile(cf *changedFile, args UploadSyncArgs, try i exponentialBackoffSleep(try) try++ return self.updateChangedFile(cf, args, try) + } else if isTimeoutError(err) { + return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout) } else { return fmt.Errorf("Failed to update file: %s", err) } diff --git a/drive/update.go b/drive/update.go index 7af403f..2ab684e 100644 --- a/drive/update.go +++ b/drive/update.go @@ -65,6 +65,9 @@ func (self *Drive) Update(args UpdateArgs) error { f, err := self.service.Files.Update(args.Id, dstFile).Fields("id", "name", "size").Context(ctx).Media(reader, chunkSize).Do() if err != nil { + if isTimeoutError(err) { + return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout) + } return fmt.Errorf("Failed to upload file: %s", err) } diff --git a/drive/upload.go b/drive/upload.go index 6f5edd5..a344b62 100644 --- a/drive/upload.go +++ b/drive/upload.go @@ -181,6 +181,9 @@ func (self *Drive) uploadFile(args UploadArgs) (*drive.File, int64, error) { f, err := self.service.Files.Create(dstFile).Fields("id", "name", "size", "md5Checksum", "webContentLink").Context(ctx).Media(reader, chunkSize).Do() if err != nil { + if isTimeoutError(err) { + return nil, 0, fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout) + } return nil, 0, fmt.Errorf("Failed to upload file: %s", err) } @@ -232,6 +235,9 @@ func (self *Drive) UploadStream(args UploadStreamArgs) error { f, err := self.service.Files.Create(dstFile).Fields("id", "name", "size", "webContentLink").Context(ctx).Media(reader, chunkSize).Do() if err != nil { + if isTimeoutError(err) { + return fmt.Errorf("Failed to upload file: timeout, no data was transferred for %v", args.Timeout) + } return fmt.Errorf("Failed to upload file: %s", err) } |
