Skip to content

Commit

Permalink
Merge pull request #7929 from kolyshkin/nits-err
Browse files Browse the repository at this point in the history
Nits
  • Loading branch information
openshift-merge-robot committed Oct 6, 2020
2 parents f584d47 + d4aa89b commit 80a2317
Show file tree
Hide file tree
Showing 62 changed files with 176 additions and 199 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func build(cmd *cobra.Command, args []string) error {
if cmd.Flag("logfile").Changed {
logfile, err := os.OpenFile(buildOpts.Logfile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600)
if err != nil {
return errors.Errorf("error opening logfile %q: %v", buildOpts.Logfile, err)
return err
}
defer logfile.Close()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func history(cmd *cobra.Command, args []string) error {
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
err = tmpl.Execute(w, hr)
if err != nil {
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Failed to print report"))
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "failed to print report"))
}
w.Flush()
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/system/connection/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func getUDS(cmd *cobra.Command, uri *url.URL) (string, error) {
value := cmd.Flag("identity").Value.String()
auth, err := terminal.PublicKey(value, []byte(passwd))
if err != nil {
return "", errors.Wrapf(err, "Failed to read identity %q", value)
return "", errors.Wrapf(err, "failed to read identity %q", value)
}
authMethods = append(authMethods, auth)
}
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ func (c *Container) setupStorage(ctx context.Context) error {

artifacts := filepath.Join(c.config.StaticDir, artifactsDir)
if err := os.MkdirAll(artifacts, 0755); err != nil {
return errors.Wrapf(err, "error creating artifacts directory %q", artifacts)
return errors.Wrap(err, "error creating artifacts directory")
}

return nil
Expand Down Expand Up @@ -1820,7 +1820,7 @@ func (c *Container) appendStringToRundir(destFile, output string) (string, error

f, err := os.OpenFile(destFileName, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
return "", errors.Wrapf(err, "unable to open %s", destFileName)
return "", err
}
defer f.Close()

Expand Down
26 changes: 10 additions & 16 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,13 @@ func (c *Container) checkpointRestoreLabelLog(fileName string) error {

logFile, err := os.OpenFile(dumpLog, os.O_CREATE, 0600)
if err != nil {
return errors.Wrapf(err, "failed to create CRIU log file %q", dumpLog)
return errors.Wrap(err, "failed to create CRIU log file")
}
if err := logFile.Close(); err != nil {
logrus.Errorf("unable to close log file: %q", err)
logrus.Error(err)
}
if err = label.SetFileLabel(dumpLog, c.MountLabel()); err != nil {
return errors.Wrapf(err, "failed to label CRIU log file %q", dumpLog)
return err
}
return nil
}
Expand Down Expand Up @@ -919,7 +919,7 @@ func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointO
func (c *Container) importCheckpoint(input string) error {
archiveFile, err := os.Open(input)
if err != nil {
return errors.Wrapf(err, "Failed to open checkpoint archive %s for import", input)
return errors.Wrap(err, "failed to open checkpoint archive for import")
}

defer archiveFile.Close()
Expand Down Expand Up @@ -1116,35 +1116,29 @@ func (c *Container) restore(ctx context.Context, options ContainerCheckpointOpti
// Only do this if a rootfs-diff.tar actually exists
rootfsDiffFile, err := os.Open(rootfsDiffPath)
if err != nil {
return errors.Wrapf(err, "Failed to open root file-system diff file %s", rootfsDiffPath)
return errors.Wrap(err, "failed to open root file-system diff file")
}
defer rootfsDiffFile.Close()
if err := c.runtime.ApplyDiffTarStream(c.ID(), rootfsDiffFile); err != nil {
return errors.Wrapf(err, "Failed to apply root file-system diff file %s", rootfsDiffPath)
return errors.Wrapf(err, "failed to apply root file-system diff file %s", rootfsDiffPath)
}
}
deletedFilesPath := filepath.Join(c.bundlePath(), "deleted.files")
if _, err := os.Stat(deletedFilesPath); err == nil {
deletedFilesFile, err := os.Open(deletedFilesPath)
if err != nil {
return errors.Wrapf(err, "Failed to open deleted files file %s", deletedFilesPath)
}
defer deletedFilesFile.Close()

var deletedFiles []string
deletedFilesJSON, err := ioutil.ReadAll(deletedFilesFile)
deletedFilesJSON, err := ioutil.ReadFile(deletedFilesPath)
if err != nil {
return errors.Wrapf(err, "Failed to read deleted files file %s", deletedFilesPath)
return errors.Wrapf(err, "failed to read deleted files file")
}
if err := json.Unmarshal(deletedFilesJSON, &deletedFiles); err != nil {
return errors.Wrapf(err, "Failed to read deleted files file %s", deletedFilesPath)
return errors.Wrapf(err, "failed to read deleted files file %s", deletedFilesPath)
}
for _, deleteFile := range deletedFiles {
// Using RemoveAll as deletedFiles, which is generated from 'podman diff'
// lists completely deleted directories as a single entry: 'D /root'.
err = os.RemoveAll(filepath.Join(c.state.Mountpoint, deleteFile))
if err != nil {
return errors.Wrapf(err, "Failed to delete file %s from container %s during restore", deletedFilesPath, c.ID())
return errors.Wrapf(err, "failed to delete file %s from container %s during restore", deletedFilesPath, c.ID())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func (i *Image) PushImageToReference(ctx context.Context, dest types.ImageRefere
// Copy the image to the remote destination
manifestBytes, err := cp.Image(ctx, policyContext, dest, src, copyOptions)
if err != nil {
return errors.Wrapf(err, "Error copying image to the remote destination")
return errors.Wrapf(err, "error copying image to the remote destination")
}
digest, err := manifest.Digest(manifestBytes)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions libpod/lock/file/file_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func CreateFileLock(path string) (*FileLocks, error) {
return nil, errors.Wrapf(syscall.EEXIST, "directory %s exists", path)
}
if err := os.MkdirAll(path, 0711); err != nil {
return nil, errors.Wrapf(err, "cannot create %s", path)
return nil, err
}

locks := new(FileLocks)
Expand All @@ -40,7 +40,7 @@ func CreateFileLock(path string) (*FileLocks, error) {
func OpenFileLock(path string) (*FileLocks, error) {
_, err := os.Stat(path)
if err != nil {
return nil, errors.Wrapf(err, "accessing directory %s", path)
return nil, err
}

locks := new(FileLocks)
Expand Down Expand Up @@ -84,7 +84,7 @@ func (locks *FileLocks) AllocateLock() (uint32, error) {
if os.IsExist(err) {
continue
}
return 0, errors.Wrapf(err, "creating lock file")
return 0, errors.Wrap(err, "creating lock file")
}
f.Close()
break
Expand Down
4 changes: 2 additions & 2 deletions libpod/networking_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,12 +662,12 @@ func (r *Runtime) setupNetNS(ctr *Container) error {
nsPath := fmt.Sprintf("/var/run/netns/cni-%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])

if err := os.MkdirAll(filepath.Dir(nsPath), 0711); err != nil {
return errors.Wrapf(err, "cannot create %s", filepath.Dir(nsPath))
return err
}

mountPointFd, err := os.Create(nsPath)
if err != nil {
return errors.Wrapf(err, "cannot open %s", nsPath)
return err
}
if err := mountPointFd.Close(); err != nil {
return err
Expand Down
10 changes: 4 additions & 6 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,13 @@ func newConmonOCIRuntime(name string, paths []string, conmonPath string, runtime
if err := os.MkdirAll(runtime.exitsDir, 0750); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating OCI runtime exit files directory %s",
runtime.exitsDir)
return nil, errors.Wrapf(err, "error creating OCI runtime exit files directory")
}
}
if err := os.MkdirAll(runtime.socketsDir, 0750); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "error creating OCI runtime attach sockets directory %s",
runtime.socketsDir)
return nil, errors.Wrap(err, "error creating OCI runtime attach sockets directory")
}
}

Expand Down Expand Up @@ -1397,12 +1395,12 @@ func startCommandGivenSelinux(cmd *exec.Cmd) error {
)
plabel, err = selinux.CurrentLabel()
if err != nil {
return errors.Wrapf(err, "Failed to get current SELinux label")
return errors.Wrapf(err, "failed to get current SELinux label")
}

con, err = selinux.NewContext(plabel)
if err != nil {
return errors.Wrapf(err, "Failed to get new context from SELinux label")
return errors.Wrapf(err, "failed to get new context from SELinux label")
}

runtime.LockOSThread()
Expand Down
14 changes: 6 additions & 8 deletions libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
if err := os.MkdirAll(runtime.config.Engine.StaticDir, 0700); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return errors.Wrapf(err, "error creating runtime static files directory %s",
runtime.config.Engine.StaticDir)
return errors.Wrap(err, "error creating runtime static files directory")
}
}

Expand Down Expand Up @@ -348,15 +347,15 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
if err := os.MkdirAll(runtime.config.Engine.TmpDir, 0751); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return errors.Wrapf(err, "error creating tmpdir %s", runtime.config.Engine.TmpDir)
return errors.Wrap(err, "error creating tmpdir")
}
}

// Create events log dir
if err := os.MkdirAll(filepath.Dir(runtime.config.Engine.EventsLogFilePath), 0700); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return errors.Wrapf(err, "error creating events dirs %s", filepath.Dir(runtime.config.Engine.EventsLogFilePath))
return errors.Wrap(err, "error creating events dirs")
}
}

Expand Down Expand Up @@ -416,8 +415,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
if err := os.MkdirAll(runtime.config.Engine.TmpDir, 0755); err != nil {
// The directory is allowed to exist
if !os.IsExist(err) {
return errors.Wrapf(err, "error creating runtime temporary files directory %s",
runtime.config.Engine.TmpDir)
return errors.Wrapf(err, "error creating runtime temporary files directory")
}
}

Expand Down Expand Up @@ -584,7 +582,7 @@ func (r *Runtime) Shutdown(force bool) error {
// attempt to shut it down
if r.store != nil {
if _, err := r.store.Shutdown(force); err != nil {
lastError = errors.Wrapf(err, "Error shutting down container storage")
lastError = errors.Wrapf(err, "error shutting down container storage")
}
}
if err := r.state.Close(); err != nil {
Expand Down Expand Up @@ -649,7 +647,7 @@ func (r *Runtime) refresh(alivePath string) error {
// Create a file indicating the runtime is alive and ready
file, err := os.OpenFile(alivePath, os.O_RDONLY|os.O_CREATE, 0644)
if err != nil {
return errors.Wrapf(err, "error creating runtime status file %s", alivePath)
return errors.Wrap(err, "error creating runtime status file")
}
defer file.Close()

Expand Down
6 changes: 3 additions & 3 deletions libpod/runtime_ctr.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
ctr.config.ShmDir = filepath.Join(ctr.bundlePath(), "shm")
if err := os.MkdirAll(ctr.config.ShmDir, 0700); err != nil {
if !os.IsExist(err) {
return nil, errors.Wrapf(err, "unable to create shm %q dir", ctr.config.ShmDir)
return nil, errors.Wrap(err, "unable to create shm dir")
}
}
ctr.config.Mounts = append(ctr.config.Mounts, ctr.config.ShmDir)
Expand Down Expand Up @@ -620,7 +620,7 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol

id, err := r.state.LookupContainerID(idOrName)
if err != nil {
return "", errors.Wrapf(err, "Failed to find container %q in state", idOrName)
return "", errors.Wrapf(err, "failed to find container %q in state", idOrName)
}

// Begin by trying a normal removal. Valid containers will be removed normally.
Expand Down Expand Up @@ -650,7 +650,7 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol
return id, err
}
if !exists {
return id, errors.Wrapf(err, "Failed to find container ID %q for eviction", id)
return id, errors.Wrapf(err, "failed to find container ID %q for eviction", id)
}

// Re-create a container struct for removal purposes
Expand Down
10 changes: 5 additions & 5 deletions pkg/api/handlers/compat/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {

if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand All @@ -59,7 +59,7 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
return
}
logrus.Warn(errors.Wrapf(err, "Failed to evict container: %q", name))
logrus.Warn(errors.Wrapf(err, "failed to evict container: %q", name))
utils.InternalServerError(w, err)
return
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
}

if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}
if query.All {
Expand Down Expand Up @@ -132,7 +132,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
}

if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func KillContainer(w http.ResponseWriter, r *http.Request) {
Signal: "KILL",
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest,
errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}
if err := json.NewDecoder(r.Body).Decode(&input); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/handlers/compat/containers_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
Tail: "all",
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand Down Expand Up @@ -93,7 +93,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {

logChannel := make(chan *logs.LogLine, tail+1)
if err := runtime.Log(r.Context(), []*libpod.Container{ctnr}, options, logChannel); err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain logs for Container '%s'", name))
utils.InternalServerError(w, errors.Wrapf(err, "failed to obtain logs for Container '%s'", name))
return
}
go func() {
Expand All @@ -111,7 +111,7 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
if !utils.IsLibpodRequest(r) {
inspectData, err := ctnr.Inspect(false)
if err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain logs for Container '%s'", name))
utils.InternalServerError(w, errors.Wrapf(err, "failed to obtain logs for Container '%s'", name))
return
}
writeHeader = !inspectData.Config.Tty
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func PruneContainers(w http.ResponseWriter, r *http.Request) {
Filters map[string][]string `schema:"filters"`
}{}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}
for k, v := range query.Filters {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func RestartContainer(w http.ResponseWriter, r *http.Request) {
// Override golang default values for types
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.BadRequest(w, "url", r.URL.String(), errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.BadRequest(w, "url", r.URL.String(), errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/handlers/compat/containers_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {
Stream: true,
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "failed to parse parameters for %s", r.URL.String()))
return
}

Expand All @@ -52,7 +52,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) {

stats, err := ctnr.GetContainerStats(&define.ContainerStats{})
if err != nil {
utils.InternalServerError(w, errors.Wrapf(err, "Failed to obtain Container %s stats", name))
utils.InternalServerError(w, errors.Wrapf(err, "failed to obtain Container %s stats", name))
return
}

Expand Down
Loading

0 comments on commit 80a2317

Please sign in to comment.