Skip to content

Commit

Permalink
Improve error output when failing initial scan upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgHaj committed Oct 10, 2023
1 parent 323ed16 commit bb2781c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,22 @@ 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)

return files, nil
}
}

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 {
Expand Down
2 changes: 2 additions & 0 deletions internal/upload/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bb2781c

Please sign in to comment.