diff --git a/pkg/bindings/containers/logs.go b/pkg/bindings/containers/logs.go index 9ebfd90dad..9d3fdb8ebe 100644 --- a/pkg/bindings/containers/logs.go +++ b/pkg/bindings/containers/logs.go @@ -35,6 +35,11 @@ func Logs(ctx context.Context, nameOrID string, options *LogOptions, stdoutChan, } defer response.Body.Close() + // if not success handle and return possible error message + if !(response.IsSuccess() || response.IsInformational()) { + return response.Process(nil) + } + buffer := make([]byte, 1024) for { fd, l, err := DemuxHeader(response.Body, buffer) diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index 5a50869e8f..46d1bd0d42 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -47,6 +47,13 @@ var _ = Describe("Podman logs", func() { }) + It("podman logs on not existent container", func() { + results := podmanTest.Podman([]string{"logs", "notexist"}) + results.WaitWithDefaultTimeout() + Expect(results).To(Exit(125)) + Expect(results.ErrorToString()).To(Equal(`Error: no container with name or ID "notexist" found: no such container`)) + }) + for _, log := range []string{"k8s-file", "journald", "json-file"} { // This is important to move the 'log' var to the correct scope under Ginkgo flow. log := log