Wrap errors in the Go 1.13 way

Signed-off-by: Julian Kornberger <jk+github@digineo.de>
This commit is contained in:
Julian Kornberger 2019-11-29 14:51:31 +01:00 committed by Johannes 'fish' Ziemke
parent da0ae76a91
commit 043fecbfd8
21 changed files with 31 additions and 31 deletions

View file

@ -36,7 +36,7 @@ type bcacheCollector struct {
func NewBcacheCollector() (Collector, error) {
fs, err := bcache.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
return &bcacheCollector{
@ -49,7 +49,7 @@ func NewBcacheCollector() (Collector, error) {
func (c *bcacheCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.Stats()
if err != nil {
return fmt.Errorf("failed to retrieve bcache stats: %v", err)
return fmt.Errorf("failed to retrieve bcache stats: %w", err)
}
for _, s := range stats {

View file

@ -47,7 +47,7 @@ func NewBuddyinfoCollector() (Collector, error) {
)
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &buddyinfoCollector{fs, desc}, nil
}

View file

@ -47,7 +47,7 @@ func init() {
func NewCPUCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &cpuCollector{
fs: fs,

View file

@ -40,7 +40,7 @@ func init() {
func NewCPUFreqCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
return &cpuFreqCollector{

View file

@ -40,7 +40,7 @@ func NewInfiniBandCollector() (Collector, error) {
i.fs, err = sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
// Detailed description for all metrics.

View file

@ -59,7 +59,7 @@ func newIPVSCollector() (*ipvsCollector, error) {
c.fs, err = procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
c.connections = typedDesc{prometheus.NewDesc(

View file

@ -94,7 +94,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error {
fs, errFs := procfs.NewFS(*procPath)
if errFs != nil {
return fmt.Errorf("failed to open procfs: %v", errFs)
return fmt.Errorf("failed to open procfs: %w", errFs)
}
mdStats, err := fs.MDStat()

View file

@ -58,7 +58,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
var bcstats C.struct_bcachestats
if _, err := C.sysctl_uvmexp(&uvmexp); err != nil {
return nil, fmt.Errorf("sysctl CTL_VM VM_UVMEXP failed: %v", err)
return nil, fmt.Errorf("sysctl CTL_VM VM_UVMEXP failed: %w", err)
}
if _, err := C.sysctl_bcstats(&bcstats); err != nil {

View file

@ -108,12 +108,12 @@ func init() {
func NewMountStatsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
proc, err := fs.Self()
if err != nil {
return nil, fmt.Errorf("failed to open /proc/self: %v", err)
return nil, fmt.Errorf("failed to open /proc/self: %w", err)
}
const (
@ -505,12 +505,12 @@ func NewMountStatsCollector() (Collector, error) {
func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error {
mounts, err := c.proc.MountStats()
if err != nil {
return fmt.Errorf("failed to parse mountstats: %v", err)
return fmt.Errorf("failed to parse mountstats: %w", err)
}
mountsInfo, err := c.proc.MountInfo()
if err != nil {
return fmt.Errorf("failed to parse mountinfo: %v", err)
return fmt.Errorf("failed to parse mountinfo: %w", err)
}
// store all seen nfsDeviceIdentifiers for deduplication

View file

@ -44,7 +44,7 @@ func init() {
func NewNetClassCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
pattern := regexp.MustCompile(*netclassIgnoredDevices)
return &netClassCollector{

View file

@ -45,7 +45,7 @@ func init() {
func NewNfsCollector() (Collector, error) {
fs, err := nfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &nfsCollector{
@ -96,7 +96,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error {
log.Debugf("Not collecting NFS metrics: %s", err)
return nil
}
return fmt.Errorf("failed to retrieve nfs stats: %v", err)
return fmt.Errorf("failed to retrieve nfs stats: %w", err)
}
c.updateNFSNetworkStats(ch, &stats.Network)

View file

@ -41,7 +41,7 @@ const (
func NewNFSdCollector() (Collector, error) {
fs, err := nfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &nfsdCollector{
@ -62,7 +62,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error {
log.Debugf("Not collecting NFSd metrics: %s", err)
return nil
}
return fmt.Errorf("failed to retrieve nfsd stats: %v", err)
return fmt.Errorf("failed to retrieve nfsd stats: %w", err)
}
c.updateNFSdReplyCacheStats(ch, &stats.ReplyCache)

View file

@ -45,7 +45,7 @@ func init() {
func NewPressureStatsCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &pressureStatsCollector{

View file

@ -41,7 +41,7 @@ func init() {
func NewProcessStatCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
subsystem := "processes"
return &processCollector{

View file

@ -49,7 +49,7 @@ var (
func NewSchedstatCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &schedstatCollector{fs: fs}, nil

View file

@ -45,7 +45,7 @@ func NewSockStatCollector() (Collector, error) {
func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return fmt.Errorf("failed to open procfs: %v", err)
return fmt.Errorf("failed to open procfs: %w", err)
}
// If IPv4 and/or IPv6 are disabled on this kernel, handle it gracefully.
@ -55,7 +55,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {
case os.IsNotExist(err):
log.Debug("IPv4 sockstat statistics not found, skipping")
default:
return fmt.Errorf("failed to get IPv4 sockstat data: %v", err)
return fmt.Errorf("failed to get IPv4 sockstat data: %w", err)
}
stat6, err := fs.NetSockstat6()
@ -64,7 +64,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error {
case os.IsNotExist(err):
log.Debug("IPv6 sockstat statistics not found, skipping")
default:
return fmt.Errorf("failed to get IPv6 sockstat data: %v", err)
return fmt.Errorf("failed to get IPv6 sockstat data: %w", err)
}
stats := []struct {

View file

@ -41,7 +41,7 @@ func init() {
func NewStatCollector() (Collector, error) {
fs, err := procfs.NewFS(*procPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %v", err)
return nil, fmt.Errorf("failed to open procfs: %w", err)
}
return &statCollector{
fs: fs,

View file

@ -40,7 +40,7 @@ func init() {
func NewThermalZoneCollector() (Collector, error) {
fs, err := sysfs.NewFS(*sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
return &thermalZoneCollector{

View file

@ -160,7 +160,7 @@ func (c *timexCollector) Update(ch chan<- prometheus.Metric) error {
status, err := unix.Adjtimex(timex)
if err != nil {
return fmt.Errorf("failed to retrieve adjtimex stats: %v", err)
return fmt.Errorf("failed to retrieve adjtimex stats: %w", err)
}
if status == timeError {

View file

@ -170,13 +170,13 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error {
return nil
}
return fmt.Errorf("failed to access wifi data: %v", err)
return fmt.Errorf("failed to access wifi data: %w", err)
}
defer stat.Close()
ifis, err := stat.Interfaces()
if err != nil {
return fmt.Errorf("failed to retrieve wifi interfaces: %v", err)
return fmt.Errorf("failed to retrieve wifi interfaces: %w", err)
}
for _, ifi := range ifis {

View file

@ -33,7 +33,7 @@ func init() {
func NewXFSCollector() (Collector, error) {
fs, err := xfs.NewFS(*procPath, *sysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %v", err)
return nil, fmt.Errorf("failed to open sysfs: %w", err)
}
return &xfsCollector{
@ -45,7 +45,7 @@ func NewXFSCollector() (Collector, error) {
func (c *xfsCollector) Update(ch chan<- prometheus.Metric) error {
stats, err := c.fs.SysStats()
if err != nil {
return fmt.Errorf("failed to retrieve XFS stats: %v", err)
return fmt.Errorf("failed to retrieve XFS stats: %w", err)
}
for _, s := range stats {