Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

janitorial: modernize error detection #233

Merged
merged 1 commit into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/gpu/gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package gpu_test

import (
"errors"
"os"
"testing"

Expand All @@ -17,7 +18,7 @@ func TestGPU(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_GPU"); ok {
t.Skip("Skipping GPU tests.")
}
if _, err := os.Stat("/sys/class/drm"); os.IsNotExist(err) {
if _, err := os.Stat("/sys/class/drm"); errors.Is(err, os.ErrNotExist) {
t.Skip("Skipping GPU tests. The environment has no /sys/class/drm directory.")
}
info, err := gpu.New()
Expand Down
3 changes: 2 additions & 1 deletion pkg/memory/memory_cache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package memory

import (
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -62,7 +63,7 @@ func CachesForNode(ctx *context.Context, nodeID int) ([]*Cache, error) {
// directories contains information about the size of that level of
// cache and the processors mapped to it.
cachePath := filepath.Join(cpuPath, "cache")
if _, err = os.Stat(cachePath); os.IsNotExist(err) {
if _, err = os.Stat(cachePath); errors.Is(err, os.ErrNotExist) {
continue
}
cacheDirFiles, err := ioutil.ReadDir(cachePath)
Expand Down
3 changes: 2 additions & 1 deletion pkg/snapshot/clonetree_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package snapshot

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -120,7 +121,7 @@ func createBlockDeviceDir(buildDeviceDir string, srcDeviceDir string) error {
// and whether the device is read-only
buf, err := ioutil.ReadFile(fp)
if err != nil {
if os.IsPermission(err) {
if errors.Is(err, os.ErrPermission) {
// example: /sys/devices/virtual/block/zram0/compact is 0400
trace("permission denied reading %q - skipped\n", fp)
continue
Expand Down
3 changes: 2 additions & 1 deletion pkg/snapshot/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package snapshot
import (
"archive/tar"
"compress/gzip"
"errors"
"fmt"
"io"
"os"
Expand All @@ -35,7 +36,7 @@ func OpenDestination(snapshotName string) (*os.File, error) {
var f *os.File
var err error

if _, err = os.Stat(snapshotName); os.IsNotExist(err) {
if _, err = os.Stat(snapshotName); errors.Is(err, os.ErrNotExist) {
if f, err = os.Create(snapshotName); err != nil {
return nil, err
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/snapshot/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package snapshot_test

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -33,7 +34,7 @@ func TestUnpack(t *testing.T) {
t.Fatalf("Expected nil err, but got %v", err)
}

if _, err := os.Stat(root); !os.IsNotExist(err) {
if _, err := os.Stat(root); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Expected %q to be gone, but still exists", root)
}
}
Expand All @@ -60,7 +61,7 @@ func TestUnpackInto(t *testing.T) {
t.Fatalf("Expected nil err, but got %v", err)
}

if _, err := os.Stat(testRoot); !os.IsNotExist(err) {
if _, err := os.Stat(testRoot); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Expected %q to be gone, but still exists", testRoot)
}
}
Expand Down Expand Up @@ -103,7 +104,7 @@ func TestUnpackIntoPresrving(t *testing.T) {
t.Fatalf("Expected nil err, but got %v", err)
}

if _, err := os.Stat(testRoot); !os.IsNotExist(err) {
if _, err := os.Stat(testRoot); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("Expected %q to be gone, but still exists", testRoot)
}
}
Expand Down