summaryrefslogtreecommitdiff
path: root/vendor/github.com/shirou/gopsutil/v4/internal/common/warnings.go
blob: 888cc57faee38abcfd48b665c83c90012d9b665c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-License-Identifier: BSD-3-Clause
package common

import "fmt"

type Warnings struct {
	List    []error
	Verbose bool
}

func (w *Warnings) Add(err error) {
	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())
		}
		return str
	}
	return fmt.Sprintf("Number of warnings: %v", len(w.List))
}