Skip to content

Commit

Permalink
podman-remote logs: handle server error correctly
Browse files Browse the repository at this point in the history
If the server responds with an error we must report it correct back to
the user.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed May 23, 2023
1 parent 9558af2 commit 5b21c38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/bindings/containers/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b21c38

Please sign in to comment.