diff --git a/internal/oci/container.go b/internal/oci/container.go index 745f895021e..021b2408c79 100644 --- a/internal/oci/container.go +++ b/internal/oci/container.go @@ -391,14 +391,9 @@ func (c *Container) exitFilePath() string { // IsAlive is a function that checks if a container's init PID exists. // It is used to check a container state when we don't want a `$runtime state` call -func (c *Container) IsAlive() bool { +func (c *Container) IsAlive() error { _, err := c.pid() - if err != nil { - logrus.Errorf("checking if PID of %s is running failed: %v", c.id, err) - return false - } - - return true + return errors.Wrapf(err, "checking if PID of %s is running failed", c.id) } // Pid returns the container's init PID. diff --git a/internal/oci/container_test.go b/internal/oci/container_test.go index fd031d2188d..72f0db51842 100644 --- a/internal/oci/container_test.go +++ b/internal/oci/container_test.go @@ -306,7 +306,7 @@ var _ = t.Describe("Container", func() { err := sut.IsAlive() // Then - Expect(err).To(Equal(false)) + Expect(err).NotTo(BeNil()) }) It("should succeed if pid is running", func() { // Given @@ -318,7 +318,7 @@ var _ = t.Describe("Container", func() { err := sut.IsAlive() // Then - Expect(err).To(Equal(true)) + Expect(err).To(BeNil()) }) It("should be false if pid is not running", func() { // Given @@ -331,7 +331,7 @@ var _ = t.Describe("Container", func() { err := sut.IsAlive() // Then - Expect(err).To(Equal(false)) + Expect(err).NotTo(BeNil()) }) }) t.Describe("Pid", func() { diff --git a/server/container_execsync.go b/server/container_execsync.go index 21071f8855b..316c0c2317a 100644 --- a/server/container_execsync.go +++ b/server/container_execsync.go @@ -1,8 +1,7 @@ package server import ( - "fmt" - + "github.com/pkg/errors" "golang.org/x/net/context" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -16,13 +15,13 @@ func (s *Server) ExecSync(ctx context.Context, req *pb.ExecSyncRequest) (*pb.Exe return nil, status.Errorf(codes.NotFound, "could not find container %q: %v", req.ContainerId, err) } - if !c.IsAlive() { - return nil, fmt.Errorf("container is not created or running") + if err := c.IsAlive(); err != nil { + return nil, status.Errorf(codes.NotFound, "container is not created or running: %v", err) } cmd := req.Cmd if cmd == nil { - return nil, fmt.Errorf("exec command cannot be empty") + return nil, errors.New("exec command cannot be empty") } execResp, err := s.Runtime().ExecSyncContainer(c, cmd, req.Timeout)