From bb2781c0d8dbd8066e929896b8e059b972c3938f Mon Sep 17 00:00:00 2001 From: ProgHaj Date: Wed, 4 Oct 2023 10:46:03 +0200 Subject: [PATCH] Improve error output when failing initial scan upload --- internal/upload/batch.go | 10 +++++++--- internal/upload/batch_test.go | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/upload/batch.go b/internal/upload/batch.go index 89691835..cec0239b 100644 --- a/internal/upload/batch.go +++ b/internal/upload/batch.go @@ -226,10 +226,12 @@ func (uploadBatch *uploadBatch) initUpload() ([]string, error) { return files, nil } + var entryFile string + var err error for len(files) > 0 { - entryFile := files[0] + entryFile = files[0] files = files[1:] - err := uploadBatch.uploadFile(entryFile) + err = uploadBatch.uploadFile(entryFile) if err == nil { printSuccessfulUpload(entryFile) @@ -237,7 +239,9 @@ func (uploadBatch *uploadBatch) initUpload() ([]string, error) { } } - return files, errors.New("failed to initialize a scan due to badly formatted files") + errStr := fmt.Sprintf("failed to initialize a scan due to badly formatted files, initial upload file %s got the following error: %s", entryFile, err.Error()) + + return files, errors.New(errStr) } type uploadedFile struct { diff --git a/internal/upload/batch_test.go b/internal/upload/batch_test.go index 4f9c446a..ba9c9bdb 100644 --- a/internal/upload/batch_test.go +++ b/internal/upload/batch_test.go @@ -102,6 +102,8 @@ func TestInitUploadBadFile(t *testing.T) { assert.Empty(t, files) assert.ErrorContains(t, err, "failed to initialize a scan due to badly formatted files") + assert.ErrorContains(t, err, "testdata/misc/requirements.txt") + assert.ErrorContains(t, err, "tried to upload empty file") } func TestInitUpload(t *testing.T) {