Skip to content

Commit

Permalink
use stacktrace.Propagate instead of fmt.Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
skylenet committed Oct 28, 2024
1 parent 922f5aa commit 26b26e9
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/docker/docker/api/types/registry"
dockerregistry "github.com/docker/docker/registry"
"github.com/kurtosis-tech/stacktrace"
)

const (
Expand All @@ -35,12 +36,12 @@ func loadDockerAuth() (RegistryAuthConfig, error) {

file, err := os.ReadFile(configFilePath)
if err != nil {
return RegistryAuthConfig{}, fmt.Errorf("error reading Docker config file: %v", err)
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error reading Docker config file")
}

var authConfig RegistryAuthConfig
if err := json.Unmarshal(file, &authConfig); err != nil {
return RegistryAuthConfig{}, fmt.Errorf("error unmarshalling Docker config file: %v", err)
return RegistryAuthConfig{}, stacktrace.Propagate(err, "error unmarshalling Docker config file")
}

return authConfig, nil
Expand All @@ -58,14 +59,14 @@ func getRegistriesFromCredsStore(credHelper string) ([]string, error) {
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("error executing credential helper %s: %v, %s", credHelperCmd, err, stderr.String())
return nil, stacktrace.Propagate(err, "error executing credential helper %s: %s", credHelperCmd, stderr.String())
}
// Output will look like this: {"https://index.docker.io/v1/":"username"}
var result map[string]string
outStr := out.String()
err := json.Unmarshal([]byte(outStr), &result)
if err != nil {
return nil, fmt.Errorf("error unmarshaling credential helper list output %s: %s, %v", credHelperCmd, outStr, err)
return nil, stacktrace.Propagate(err, "error unmarshaling credential helper list output %s: %s", credHelperCmd, outStr)
}

registries := []string{}
Expand All @@ -90,7 +91,7 @@ func getCredentialsFromStore(credHelper string, registryURL string) (*registry.A
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("error executing credential helper %s: %v, %s", credHelperCmd, err, stderr.String())
return nil, stacktrace.Propagate(err, "error executing credential helper %s: %s", credHelperCmd, stderr.String())
}

// Parse the output (it should return JSON containing "Username", "Secret" and "ServerURL")
Expand All @@ -101,7 +102,7 @@ func getCredentialsFromStore(credHelper string, registryURL string) (*registry.A
}{}

if err := json.Unmarshal(out.Bytes(), &creds); err != nil {
return nil, fmt.Errorf("error parsing credentials from store: %v", err)
return nil, stacktrace.Propagate(err, "error parsing credentials from store")
}

return &registry.AuthConfig{
Expand Down

0 comments on commit 26b26e9

Please sign in to comment.