Skip to content

Commit

Permalink
improving command error message info
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhiqiangcs committed Jan 13, 2024
1 parent 30f2d5a commit 2db3121
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zk
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
Expand Down
13 changes: 11 additions & 2 deletions zfs/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package zfs

import (
"bufio"
"io"
"os/exec"
"strings"

"github.com/pkg/errors"
)

// PoolStatus enum contains status text
Expand Down Expand Up @@ -68,17 +71,23 @@ func poolNames() ([]string, error) {
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(out)

if err = cmd.Start(); err != nil {
return nil, err
return nil, errors.Wrapf(err, "Failed to start command %s", cmd.String())
}

for scanner.Scan() {
pools = append(pools, scanner.Text())
}

stde, _ := io.ReadAll(stderr)
if err = cmd.Wait(); err != nil {
return nil, err
return nil, errors.Wrapf(err, `Failed to wait command %s, err output: "%s"`, cmd.String(), string(stde))
}

return pools, nil
Expand Down

0 comments on commit 2db3121

Please sign in to comment.