mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-26 13:48:59 +08:00
Merge pull request #1194 from mmorel-35/master
Enable errorlint and gci linters
This commit is contained in:
commit
69ea4bfdae
@ -1,4 +1,9 @@
|
||||
linters:
|
||||
enable:
|
||||
- errorlint
|
||||
- gci
|
||||
- gosimple
|
||||
- typecheck
|
||||
disable:
|
||||
- deadcode
|
||||
- errcheck
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cpu
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
@ -12,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@ -224,7 +225,8 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
||||
filename := common.HostProc("1/mountinfo")
|
||||
lines, err := common.ReadLines(filename)
|
||||
if err != nil {
|
||||
if err != err.(*os.PathError) {
|
||||
var pathErr *os.PathError
|
||||
if !errors.As(err, &pathErr) {
|
||||
return nil, err
|
||||
}
|
||||
// if kernel does not support 1/mountinfo, fallback to 1/mounts (<2.6.26)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package disk
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sync"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
19
host/host.go
19
host/host.go
@ -3,6 +3,7 @@ package host
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
@ -70,47 +71,47 @@ func InfoWithContext(ctx context.Context) (*InfoStat, error) {
|
||||
}
|
||||
|
||||
ret.Hostname, err = os.Hostname()
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.Platform, ret.PlatformFamily, ret.PlatformVersion, err = PlatformInformationWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.KernelVersion, err = KernelVersionWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.KernelArch, err = KernelArch()
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.VirtualizationSystem, ret.VirtualizationRole, err = VirtualizationWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.BootTime, err = BootTimeWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.Uptime, err = UptimeWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.Procs, err = numProcs(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret.HostID, err = HostIDWithContext(ctx)
|
||||
if err != nil && err != common.ErrNotImplementedError {
|
||||
if err != nil && !errors.Is(err, common.ErrNotImplementedError) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package host
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package common_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -13,7 +14,7 @@ func TestSleep(test *testing.T) {
|
||||
var t = func(name string, ctx context.Context, expected error) {
|
||||
test.Run(name, func(test *testing.T) {
|
||||
var err = common.Sleep(ctx, dt)
|
||||
if err != expected {
|
||||
if !errors.Is(err, expected) {
|
||||
test.Errorf("expected %v, got %v", expected, err)
|
||||
}
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package load
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@ -8,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t testing.TB, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package mem
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
@ -10,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ func connectionsPidMaxWithoutUidsWithContext(ctx context.Context, kind string, p
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cound not get pid(s), %d: %s", pid, err)
|
||||
return nil, fmt.Errorf("cound not get pid(s), %d: %w", pid, err)
|
||||
}
|
||||
return statsFromInodes(root, pid, tmap, inodes, skipUids)
|
||||
}
|
||||
@ -672,7 +672,7 @@ func getProcInodesAll(root string, max int) (map[string][]inodeMap, error) {
|
||||
t, err := getProcInodes(root, pid, max)
|
||||
if err != nil {
|
||||
// skip if permission error or no longer exists
|
||||
if os.IsPermission(err) || os.IsNotExist(err) || err == io.EOF {
|
||||
if os.IsPermission(err) || os.IsNotExist(err) || errors.Is(err, io.EOF) {
|
||||
continue
|
||||
}
|
||||
return ret, err
|
||||
@ -702,7 +702,7 @@ func decodeAddress(family uint32, src string) (Addr, error) {
|
||||
}
|
||||
decoded, err := hex.DecodeString(addr)
|
||||
if err != nil {
|
||||
return Addr{}, fmt.Errorf("decode error, %s", err)
|
||||
return Addr{}, fmt.Errorf("decode error, %w", err)
|
||||
}
|
||||
var ip net.IP
|
||||
// Assumes this is little_endian
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
p2, err := NewProcessWithContext(ctx, p.Pid)
|
||||
if err == ErrorProcessNotRunning {
|
||||
if errors.Is(err, ErrorProcessNotRunning) {
|
||||
return false, nil
|
||||
}
|
||||
createTime2, err := p2.CreateTimeWithContext(ctx)
|
||||
|
@ -4,6 +4,7 @@ package process
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/user"
|
||||
@ -122,8 +123,8 @@ func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
|
||||
if err.Error() == "os: process already finished" {
|
||||
return false, nil
|
||||
}
|
||||
errno, ok := err.(syscall.Errno)
|
||||
if !ok {
|
||||
var errno syscall.Errno
|
||||
if !errors.As(err, &errno) {
|
||||
return false, err
|
||||
}
|
||||
switch errno {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package process
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@ -23,7 +24,7 @@ import (
|
||||
var mu sync.Mutex
|
||||
|
||||
func skipIfNotImplementedErr(t *testing.T, err error) {
|
||||
if err == common.ErrNotImplementedError {
|
||||
if errors.Is(err, common.ErrNotImplementedError) {
|
||||
t.Skip("not implemented")
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user