Skip to content

Commit

Permalink
review comments: use slice to append errors
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshuraj1333 committed Sep 1, 2023
1 parent 11f0123 commit e481279
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions receiver/scraperhelper/scrapercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func (sc *controller) Shutdown(ctx context.Context) error {
<-sc.terminated
}

var errs error
var errs []error
for _, scraper := range sc.scrapers {
errs = errors.Join(errs, scraper.Shutdown(ctx))
errs = append(errs, scraper.Shutdown(ctx))
}

return errs
return errors.Join(errs...)
}

// startScraping initiates a ticker that calls Scrape based on the configured
Expand Down
6 changes: 3 additions & 3 deletions receiver/scraperhelper/scrapercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ func getExpectedStartErr(test metricsTestCase) error {
}

func getExpectedShutdownErr(test metricsTestCase) error {
var errs error
var errs []error

if test.closeErr != nil {
for i := 0; i < test.scrapers; i++ {
errs = errors.Join(errs, test.closeErr)
errs = append(errs, test.closeErr)
}
}

return errs
return errors.Join(errs...)
}

func assertChannelsCalled(t *testing.T, chs []chan bool, message string) {
Expand Down
9 changes: 5 additions & 4 deletions receiver/scraperhelper/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ func NewDefaultScraperControllerSettings(component.Type) ScraperControllerSettin
}
}

func (set *ScraperControllerSettings) Validate() (errs error) {
func (set *ScraperControllerSettings) Validate() error {
var errs []error
if set.CollectionInterval <= 0 {
errs = errors.Join(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval))
errs = append(errs, fmt.Errorf(`"collection_interval": %w`, errNonPositiveInterval))
}
if set.Timeout < 0 {
errs = errors.Join(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval))
errs = append(errs, fmt.Errorf(`"timeout": %w`, errNonPositiveInterval))
}
return errs
return errors.Join(errs...)
}

0 comments on commit e481279

Please sign in to comment.