mirror of https://github.com/shirou/gopsutil
Fix for #665
Remains backward compatible. When encountering non-fatal errors SensorsTemperatures() returns the temperatures for all the sensor we could read successfully. In that case the custom error contains a list of all the non-fatal errors encountered. Example usage: _, err := SensorsTemperatures() if err != nil { warns, ok := err.(*Warnings) if ok { fmt.Printf("%v\n", err) for i, w := range warns.List { fmt.Printf("Warning %v: %v\n", i+1, w) } } else { t.Errorf("%v", err) } }pull/675/head
parent
2cbc9195c8
commit
174b31f146
@ -0,0 +1,25 @@
|
||||
package host
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Warnings struct {
|
||||
List []error
|
||||
}
|
||||
|
||||
func (w *Warnings) Add(err error) {
|
||||
w.List = append(w.List, err)
|
||||
}
|
||||
|
||||
func (w *Warnings) Reference() error {
|
||||
if len(w.List) > 0 {
|
||||
return w
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Warnings) Error() string {
|
||||
return fmt.Sprintf("Number of warnings: %v", len(w.List))
|
||||
}
|
Loading…
Reference in New Issue