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