"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fs/rc/jobs: ExecuteJob propagate the error returned by function
Michał Matczuk3247e69cf560
diff --git a/fs/rc/jobs/job.go b/fs/rc/jobs/job.goindex 186127d0f..30c80cf91 100644--- a/fs/rc/jobs/job.go+++ b/fs/rc/jobs/job.go@@ -29,6 +29,11 @@ type Job struct {Duration float64 `json:"duration"`Output rc.Params `json:"output"`Stop func() `json:"-"`++ // realErr is the Error before printing it as a string, it's used to return+ // the real error to the upper application layers while still printing the+ // string error message.+ realErr error}// Jobs describes a collection of running tasks@@ -122,9 +127,11 @@ func (job *Job) finish(out rc.Params, err error) {job.Output = outjob.Duration = job.EndTime.Sub(job.StartTime).Seconds()if err != nil {+ job.realErr = errjob.Error = err.Error()job.Success = false} else {+ job.realErr = niljob.Error = ""job.Success = true}@@ -221,11 +228,7 @@ func StartAsyncJob(fn rc.Func, in rc.Params) (rc.Params, error) {func ExecuteJob(ctx context.Context, fn rc.Func, in rc.Params) (rc.Params, int64, error) {job, ctx := running.NewSyncJob(ctx, in)job.run(ctx, fn, in)- var err error- if !job.Success {- err = errors.New(job.Error)- }- return job.Output, job.ID, err+ return job.Output, job.ID, job.realErr}func init() {diff --git a/fs/rc/jobs/job_test.go b/fs/rc/jobs/job_test.goindex 3125c6cf4..dbd82e773 100644--- a/fs/rc/jobs/job_test.go+++ b/fs/rc/jobs/job_test.go@@ -213,6 +213,17 @@ func TestExecuteJob(t *testing.T) {assert.Equal(t, int64(1), id)}+func TestExecuteJobErrorPropagation(t *testing.T) {+ jobID = 0++ testErr := errors.New("test error")+ errorFn := func(ctx context.Context, in rc.Params) (out rc.Params, err error) {+ return nil, testErr+ }+ _, _, err := ExecuteJob(context.Background(), errorFn, rc.Params{})+ assert.Equal(t, testErr, err)+}+func TestRcJobStatus(t *testing.T) {jobID = 0_, err := StartAsyncJob(longFn, rc.Params{})