Debian Codegraph @

scraper/scrapererror/scrapeerror.go

raw
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package scrapererror // import "go.opentelemetry.io/collector/scraper/scrapererror"
5
6 import (
7 "go.uber.org/multierr"
8 )
9
10 // ScrapeErrors contains multiple PartialScrapeErrors and can also contain generic errors.
11 type ScrapeErrors struct {
12 errs []error
13 failedScrapeCount int
14 }
15
16 // AddPartial adds a PartialScrapeError with the provided failed count and error.
17 func (s *ScrapeErrors) AddPartial(failed int, err error) {
18 s.errs = append(s.errs, NewPartialScrapeError(err, failed))
19 s.failedScrapeCount += failed
20 }
21
22 // Add adds a regular error.
23 func (s *ScrapeErrors) Add(err error) {
24 s.errs = append(s.errs, err)
25 }
26
27 // Combine converts a slice of errors into one error.
28 // It will return a PartialScrapeError if at least one error in the slice is a PartialScrapeError.
29 func (s *ScrapeErrors) Combine() error {
30 partialScrapeErr := false
31 for _, err := range s.errs {
32 if IsPartialScrapeError(err) {
33 partialScrapeErr = true
34 }
35 }
36
37 combined := multierr.Combine(s.errs...)
38 if !partialScrapeErr {
39 return combined
40 }
41
42 return NewPartialScrapeError(combined, s.failedScrapeCount)
43 }