From: Simon Ruderich Date: Wed, 12 May 2021 06:32:51 +0000 (+0200) Subject: Consistently use %v when (s)printing errors X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=184dff6d9bd322819d25e4dfdf0a69f2a163974b;p=safcm%2Fsafcm.git Consistently use %v when (s)printing errors Most of the code already used %v. --- diff --git a/cmd/safcm-remote/run/cmd.go b/cmd/safcm-remote/run/cmd.go index 36e4e75..8f3d613 100644 --- a/cmd/safcm-remote/run/cmd.go +++ b/cmd/safcm-remote/run/cmd.go @@ -62,7 +62,7 @@ func (c *Cmd) Run(module string, args ...string) ([]byte, []byte, error) { } if err != nil { return nil, nil, fmt.Errorf( - "%s failed: %s; stdout: %q, stderr: %q", + "%s failed: %v; stdout: %q, stderr: %q", quoted, err, stdout.String(), stderr.String()) } return stdout.Bytes(), stderr.Bytes(), nil @@ -78,7 +78,7 @@ func (c *Cmd) CombinedOutputCmd(module string, cmd *exec.Cmd) ([]byte, error) { c.logger.Debug2f("%s: command output:\n%s", module, out) } if err != nil { - return nil, fmt.Errorf("%s failed: %s; output: %q", + return nil, fmt.Errorf("%s failed: %v; output: %q", quoted, err, out) } return out, nil diff --git a/cmd/safcm-remote/sync/sync.go b/cmd/safcm-remote/sync/sync.go index 91e24fd..6835ca4 100644 --- a/cmd/safcm-remote/sync/sync.go +++ b/cmd/safcm-remote/sync/sync.go @@ -51,28 +51,28 @@ func Handle(req safcm.MsgSyncReq, err := s.setDefaults() if err != nil { - s.resp.Error = fmt.Sprintf("%s", err) + s.resp.Error = fmt.Sprintf("%v", err) return s.resp } err = s.syncFiles() if err != nil { - s.resp.Error = fmt.Sprintf("files: %s", err) + s.resp.Error = fmt.Sprintf("files: %v", err) return s.resp } err = s.syncPackages() if err != nil { - s.resp.Error = fmt.Sprintf("packages: %s", err) + s.resp.Error = fmt.Sprintf("packages: %v", err) return s.resp } err = s.syncServices() if err != nil { - s.resp.Error = fmt.Sprintf("services: %s", err) + s.resp.Error = fmt.Sprintf("services: %v", err) return s.resp } err = s.syncCommands() if err != nil { - s.resp.Error = fmt.Sprintf("commands: %s", err) + s.resp.Error = fmt.Sprintf("commands: %v", err) return s.resp } return s.resp diff --git a/testutil/testutil.go b/testutil/testutil.go index a2e83f1..1722fd5 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -37,8 +37,8 @@ func AssertErrorEqual(t *testing.T, name string, act, exp error) { t.Helper() // Ugly but the simplest way to compare errors (including nil) - actStr := fmt.Sprintf("%s", act) - expStr := fmt.Sprintf("%s", exp) + actStr := fmt.Sprintf("%v", act) + expStr := fmt.Sprintf("%v", exp) if actStr != expStr { t.Errorf("err = %s (%#v), want %s (%#v)", actStr, act, expStr, exp)