Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert GitHub refactor (#2379) (including followups) #2669

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions pkg/sources/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package sources

import (
"errors"
"strings"
"fmt"
"sync"
)

Expand All @@ -20,10 +20,6 @@ func NewScanErrors() *ScanErrors {

// Add an error to the collection in a thread-safe manner.
func (s *ScanErrors) Add(err error) {
if err == nil {
return
}

s.mu.Lock()
defer s.mu.Unlock()
s.errors = append(s.errors, err)
Expand All @@ -39,17 +35,7 @@ func (s *ScanErrors) Count() uint64 {
func (s *ScanErrors) String() string {
s.mu.RLock()
defer s.mu.RUnlock()

var sb strings.Builder
sb.WriteString("[")
for i, err := range s.errors {
sb.WriteString(`"` + err.Error() + `"`)
if i < len(s.errors)-1 {
sb.WriteString(", ")
}
}
sb.WriteString("]")
return sb.String()
return fmt.Sprintf("%v", s.errors)
}

func (s *ScanErrors) Errors() error {
Expand Down
10 changes: 4 additions & 6 deletions pkg/sources/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"testing"
)

var testError = fmt.Errorf("simulated failure")

func TestNewScanErrors(t *testing.T) {
testCases := []struct {
name string
Expand Down Expand Up @@ -86,7 +84,7 @@ func TestScanErrorsAdd(t *testing.T) {
wg.Add(1)
go func() {
for j := 0; j < tc.wantErr/tc.concurrency; j++ {
se.Add(testError)
se.Add(nil)
}
wg.Done()
}()
Expand Down Expand Up @@ -137,7 +135,7 @@ func TestScanErrorsCount(t *testing.T) {
wg.Add(1)
go func() {
for j := 0; j < tc.wantErrCnt/tc.concurrency; j++ {
se.Add(testError)
se.Add(nil)
}
wg.Done()
}()
Expand All @@ -153,8 +151,8 @@ func TestScanErrorsCount(t *testing.T) {

func TestScanErrorsString(t *testing.T) {
se := NewScanErrors()
se.Add(testError)
want := `["` + testError.Error() + `"]`
se.Add(nil)
want := "[<nil>]"
if got := fmt.Sprintf("%v", se); got != want {
t.Errorf("got %q, want %q", got, want)
}
Expand Down
Loading
Loading