diff --git a/pkg/credentials/error.go b/pkg/credentials/error.go new file mode 100644 index 00000000..f3990f7c --- /dev/null +++ b/pkg/credentials/error.go @@ -0,0 +1,12 @@ +package credentials + +import ( + "strings" +) + +func IsCredentialsNotFoundError(err error) bool { + if err == nil { + return false + } + return strings.Contains(err.Error(), "credentials not found in native keychain") +} diff --git a/pkg/credentials/store.go b/pkg/credentials/store.go index 56555cd4..53e81f6b 100644 --- a/pkg/credentials/store.go +++ b/pkg/credentials/store.go @@ -9,7 +9,6 @@ import ( "github.com/docker/cli/cli/config/credentials" "github.com/docker/cli/cli/config/types" "github.com/docker/docker-credential-helpers/client" - credentials2 "github.com/docker/docker-credential-helpers/credentials" "github.com/gptscript-ai/gptscript/pkg/config" "golang.org/x/exp/maps" ) @@ -50,7 +49,7 @@ func (s Store) Get(_ context.Context, toolName string) (*Credential, bool, error for _, c := range s.credCtxs { auth, err := store.Get(toolNameWithCtx(toolName, c)) if err != nil { - if credentials2.IsErrCredentialsNotFound(err) { + if IsCredentialsNotFoundError(err) { continue } return nil, false, err diff --git a/pkg/credentials/toolstore.go b/pkg/credentials/toolstore.go index 3e31ea12..5f910069 100644 --- a/pkg/credentials/toolstore.go +++ b/pkg/credentials/toolstore.go @@ -30,7 +30,7 @@ func (h *toolCredentialStore) Erase(serverAddress string) error { func (h *toolCredentialStore) Get(serverAddress string) (types.AuthConfig, error) { creds, err := client.Get(h.program, serverAddress) - if credentials2.IsErrCredentialsNotFound(err) { + if IsCredentialsNotFoundError(err) { return h.file.Get(serverAddress) } else if err != nil { return types.AuthConfig{}, err diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 37a90d48..fc5737ef 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -872,7 +872,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env } else if credentialAlias != "" { c, exists, err = r.credStore.Get(callCtx.Ctx, credentialAlias) if err != nil { - return nil, fmt.Errorf("failed to get credentials for tool %s: %w", credentialAlias, err) + return nil, fmt.Errorf("failed to get credential %s: %w", credentialAlias, err) } }