From 33ddf8ee9c74376fe9eadba55ba3e5d96c0d79ca Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 10 Jun 2020 11:05:41 +0200 Subject: [PATCH] generate systemd: wrap pod/ctr lookup errors Signed-off-by: Valentin Rothberg --- pkg/domain/infra/abi/generate.go | 7 ++++--- pkg/systemd/generate/common.go | 2 +- pkg/systemd/generate/pods.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/domain/infra/abi/generate.go b/pkg/domain/infra/abi/generate.go index fa0cfb389847..8853303d5905 100644 --- a/pkg/domain/infra/abi/generate.go +++ b/pkg/domain/infra/abi/generate.go @@ -16,8 +16,8 @@ import ( func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) { // First assume it's a container. - ctr, err := ic.Libpod.LookupContainer(nameOrID) - if err == nil { + ctr, ctrErr := ic.Libpod.LookupContainer(nameOrID) + if ctrErr == nil { // Generate the unit for the container. s, err := generate.ContainerUnit(ctr, options) if err == nil { @@ -28,7 +28,8 @@ func (ic *ContainerEngine) GenerateSystemd(ctx context.Context, nameOrID string, // If it's not a container, we either have a pod or garbage. pod, err := ic.Libpod.LookupPod(nameOrID) if err != nil { - return nil, errors.Errorf("%q does not refer to a container or pod", nameOrID) + err = errors.Wrap(ctrErr, err.Error()) + return nil, errors.Wrapf(err, "%s does not refer to a container or pod", nameOrID) } // Generate the units for the pod and all its containers. diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go index 4f995be9681f..fe56dc874b4d 100644 --- a/pkg/systemd/generate/common.go +++ b/pkg/systemd/generate/common.go @@ -41,7 +41,7 @@ func filterPodFlags(command []string) []string { for i := 0; i < len(command); i++ { s := command[i] if s == "--pod" || s == "--pod-id-file" { - i += 1 + i++ continue } processed = append(processed, s) diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go index 355103df8dc2..5cfd5ab0a1c7 100644 --- a/pkg/systemd/generate/pods.go +++ b/pkg/systemd/generate/pods.go @@ -99,7 +99,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (string, // Error out if the pod has no infra container, which we require to be the // main service. if !pod.HasInfraContainer() { - return "", fmt.Errorf("error generating systemd unit files: Pod %q has no infra container", pod.Name()) + return "", errors.Errorf("error generating systemd unit files: Pod %q has no infra container", pod.Name()) } podInfo, err := generatePodInfo(pod, options) @@ -118,7 +118,7 @@ func PodUnits(pod *libpod.Pod, options entities.GenerateSystemdOptions) (string, return "", err } if len(containers) == 0 { - return "", fmt.Errorf("error generating systemd unit files: Pod %q has no containers", pod.Name()) + return "", errors.Errorf("error generating systemd unit files: Pod %q has no containers", pod.Name()) } graph, err := libpod.BuildContainerGraph(containers) if err != nil {