Files
MarioandGitHub e0354d1bed Update Prometheus to v0.307.2, OTel collector contrib to v0.138.0, OTel to v1.44.0 (#5810)
* Update Prometheus to v0.307.2

* Update otel collector

* Update OTel collector
2025-10-28 11:30:17 +01:00

49 lines
1.1 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package common
import "fmt"
const (
maxWarnings = 100 // An arbitrary limit to avoid excessive memory usage, it has no sense to store hundreds of errors
tooManyErrorsMessage = "too many errors reported, next errors were discarded"
numberOfWarningsMessage = "Number of warnings:"
)
type Warnings struct {
List []error
tooManyErrors bool
Verbose bool
}
func (w *Warnings) Add(err error) {
if len(w.List) >= maxWarnings {
w.tooManyErrors = true
return
}
w.List = append(w.List, err)
}
func (w *Warnings) Reference() error {
if len(w.List) > 0 {
return w
}
return nil
}
func (w *Warnings) Error() string {
if w.Verbose {
str := ""
for i, e := range w.List {
str += fmt.Sprintf("\tError %d: %s\n", i, e.Error())
}
if w.tooManyErrors {
str += fmt.Sprintf("\t%s\n", tooManyErrorsMessage)
}
return str
}
if w.tooManyErrors {
return fmt.Sprintf("%s > %v - %s", numberOfWarningsMessage, maxWarnings, tooManyErrorsMessage)
}
return fmt.Sprintf("%s %v", numberOfWarningsMessage, len(w.List))
}