Skip to content

Commit

Permalink
composefs: return mkcomposefs stderr as part of error
Browse files Browse the repository at this point in the history
Writing the error to stderr is not helpful when using the podman API.
The error would only be visable on the server which is bad and likely is
not noticed at all.

Also for the regular podman cli it would be hard for a user to know if
the stderr from mkcompose is related to the returned podman error.

To fix this capture the stderr and append it to the error as string,
this should be fine assuming mkcomposefs doesn't print a ton on stderr
which I assume is not the case.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 committed Apr 18, 2024
1 parent 0b293c3 commit 2a4b851
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions drivers/overlay/composefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
package overlay

import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"sync"

"github.com/containers/storage/pkg/chunked/dump"
Expand Down Expand Up @@ -70,12 +72,18 @@ func generateComposeFsBlob(verityDigests map[string]string, toc interface{}, com
// a scope to close outFd before setting fsverity on the read-only fd.
defer outFd.Close()

errBuf := &bytes.Buffer{}
cmd := exec.Command(writerJson, "--from-file", "-", "/proc/self/fd/3")
cmd.ExtraFiles = []*os.File{outFd}
cmd.Stderr = os.Stderr
cmd.Stderr = errBuf
cmd.Stdin = dumpReader
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to convert json to erofs: %w", err)
rErr := fmt.Errorf("failed to convert json to erofs: %w", err)
exitErr := &exec.ExitError{}
if errors.As(err, &exitErr) {
return fmt.Errorf("%w: %s", rErr, strings.TrimSpace(errBuf.String()))
}
return rErr
}
return nil
}()
Expand Down

0 comments on commit 2a4b851

Please sign in to comment.