Skip to content
8 changes: 5 additions & 3 deletions internal/pkg/cli/command/apiKey/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
Expand Down Expand Up @@ -64,14 +65,14 @@ func NewCreateApiKeyCmd() *cobra.Command {
projId, err = state.GetTargetProjectId()
if err != nil {
msg.FailMsg("No target project set, and no project ID provided. Use %s to set the target project. Use %s to create the key in a specific project.", style.Code("pc target -o <org> -p <project>"), style.Code("pc api-key create -i <project-id> -n <name>"))
exit.ErrorMsg("No project ID provided, and no target project set")
exit.Error().Err(err).Msg("No project ID provided, and no target project set")
}
}

targetOrgId, err := state.GetTargetOrgId()
if err != nil {
msg.FailMsg("Failed to get target organization ID: %s", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to get target organization ID")
}

// Only set non-empty values
Expand All @@ -89,7 +90,7 @@ func NewCreateApiKeyCmd() *cobra.Command {
keyWithSecret, err := ac.APIKey.Create(cmd.Context(), projId, createParams)
if err != nil {
msg.FailMsg("Failed to create API key %s in project %s: %s", options.name, projId, err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to create API key %s in project %s", options.name, projId)
}

if options.json {
Expand All @@ -108,6 +109,7 @@ func NewCreateApiKeyCmd() *cobra.Command {
err := ac.APIKey.Delete(cmd.Context(), managedKey.Id)
if err != nil {
msg.FailMsg("Failed to delete previously managed API key: %s, %+v", style.Emphasis(managedKey.Id), err)
log.Error().Err(err).Msg("Failed to delete previously managed API key")
}
msg.SuccessMsg("Deleted previously managed API key: %s", style.Emphasis(managedKey.Id))
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/cli/command/apiKey/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewDeleteKeyCmd() *cobra.Command {
keyToDelete, err := ac.APIKey.Describe(cmd.Context(), options.apiKeyId)
if err != nil {
msg.FailMsg("Failed to describe existing API key: %s", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to describe existing API key")
}

if !options.skipConfirmation {
Expand All @@ -64,7 +64,7 @@ func NewDeleteKeyCmd() *cobra.Command {
err = ac.APIKey.Delete(cmd.Context(), keyToDelete.Id)
if err != nil {
msg.FailMsg("Failed to delete API key %s: %s", style.Emphasis(keyToDelete.Name), err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to delete API key %s", keyToDelete.Name)
}
msg.SuccessMsg("API key %s deleted", style.Emphasis(keyToDelete.Name))

Expand Down Expand Up @@ -96,8 +96,8 @@ func confirmDeleteApiKey(apiKeyName string) {
reader := bufio.NewReader(os.Stdin)
input, err := reader.ReadString('\n')
if err != nil {
fmt.Println("Error reading input:", err)
return
msg.FailMsg("Error reading input: %+v", err)
exit.Error().Err(err).Msg("Error reading input")
}

// Trim any whitespace from the input and convert to lowercase
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/apiKey/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewDescribeAPIKeyCmd() *cobra.Command {
apiKey, err := ac.APIKey.Describe(cmd.Context(), options.apiKeyID)
if err != nil {
msg.FailMsg("Failed to describe API key %s: %s\n", style.Emphasis(options.apiKeyID), err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to describe API key %s", options.apiKeyID)
}

if options.json {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/apiKey/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewListKeysCmd() *cobra.Command {
keysResponse, err := ac.APIKey.List(cmd.Context(), projId)
if err != nil {
msg.FailMsg("Failed to list API keys: %s", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to list API keys")
}

// Sort keys alphabetically by name
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/apiKey/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewUpdateAPIKeyCmd() *cobra.Command {
apiKey, err := ac.APIKey.Update(cmd.Context(), options.apiKeyID, updateParams)
if err != nil {
msg.FailMsg("Failed to update API key %s: %s\n", options.apiKeyID, err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to update API key %s", options.apiKeyID)
}

if options.json {
Expand Down
25 changes: 11 additions & 14 deletions internal/pkg/cli/command/auth/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,25 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) {
if opts.readSecretFromStdin {
secretBytes, err := ioReadAll(io.In)
if err != nil {
log.Error().Err(err).Msg("Error reading client secret from stdin")
exit.Error(pcio.Errorf("error reading client secret from stdin: %w", err))
msg.FailMsg("Error reading client secret from stdin: %+v", err)
exit.Error().Err(err).Msg("Error reading client secret from stdin")
}
clientSecret = string(secretBytes)
} else if opts.promptIfMissing && isTerminal(os.Stdin) {
pcio.Fprint(io.Out, "Client Secret: ")
secretBytes, err := term.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
log.Error().Err(err).Msg("Error reading client secret from terminal")
exit.Error(pcio.Errorf("error reading client secret from terminal: %w", err))
msg.FailMsg("Error reading client secret from terminal: %+v", err)
exit.Error().Err(err).Msg("Error reading client secret from terminal")
}
clientSecret = string(secretBytes)
}
}

// If client_id is provided without a client_secret, error
if clientID != "" && clientSecret == "" {
log.Error().Msg("Error configuring authentication credentials")
if !opts.json {
msg.FailMsg("Client secret is required (use %s or %s to provide it)", style.Emphasis("--client-secret"), style.Emphasis("--client-secret-stdin"))
}
exit.Error(pcio.Errorf("client secret is required"))
msg.FailMsg("Client secret is required (use %s or %s to provide it)", style.Emphasis("--client-secret"), style.Emphasis("--client-secret-stdin"))
exit.Error().Msgf("error configuring authentication credentials Client secret is required (use %s or %s to provide it)", style.Emphasis("--client-secret"), style.Emphasis("--client-secret-stdin"))
return
}

Expand All @@ -147,12 +144,12 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) {
// There should only be one organization listed for a service account
orgs, err := ac.Organization.List(ctx)
if err != nil {
log.Error().Err(err).Msg("Error listing service account organizations")
exit.Error(pcio.Errorf("Error listing service account organizations: %w", err))
msg.FailMsg("Error listing service account organizations: %+v", err)
exit.Error().Err(err).Msg("Error listing service account organizations")
}

if len(orgs) == 0 {
log.Error().Msg("No organizations found for service account")
msg.FailMsg("No organizations found for service account")
exit.ErrorMsg("No organizations found for service account")
}

Expand All @@ -169,8 +166,8 @@ func Run(ctx context.Context, io IO, opts configureCmdOptions) {
// List projects, and allow the user to pick one, or match the project-id if provided through the command
projects, err := ac.Project.List(ctx)
if err != nil {
log.Error().Err(err).Msg("Error listing projects for service account")
exit.Error(pcio.Errorf("Error listing projects for service account: %w", err))
msg.FailMsg("Error listing projects for service account")
exit.Error().Err(err).Msg("Error listing projects for service account")
}

var targetProject *pinecone.Project
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/cli/command/auth/local_keys_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func runPruneLocalKeys(ctx context.Context, options pruneLocalKeysCmdOptions) {
managedKeys = map[string]secrets.ManagedKey{options.projectID: mk}
} else {
msg.FailMsg("No managed keys found for project ID %s", style.Emphasis(options.projectID))
exit.Error(pcio.Errorf("no managed keys found for project ID: %s", options.projectID))
exit.Error().Msgf("no managed keys found for project ID: %s", options.projectID)
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func runPruneLocalKeys(ctx context.Context, options pruneLocalKeysCmdOptions) {
confirmed, err := confirmPruneKeys(plan, options)
if err != nil {
msg.FailMsg("Failed to confirm pruning keys: %s", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to confirm pruning keys")
}
shouldPrune = confirmed
}
Expand All @@ -149,7 +149,7 @@ func runPruneLocalKeys(ctx context.Context, options pruneLocalKeysCmdOptions) {
if key.onServer {
if err := ac.APIKey.Delete(ctx, key.managedKey.Id); err != nil {
msg.FailMsg("Failed to delete remote key %s: %v", style.Emphasis(key.managedKey.Id), err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to delete remote key %s", key.managedKey.Id)
continue // If we failed to delete the remote key, move on and keep the locally stored key for now
}
msg.SuccessMsg("Deleted remote key %s (project %s)", style.Emphasis(key.managedKey.Id), style.Emphasis(key.projectID))
Expand Down
6 changes: 3 additions & 3 deletions internal/pkg/cli/command/auth/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pinecone-io/cli/internal/pkg/utils/configuration/state"
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/oauth"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/presenters"
Expand All @@ -31,8 +31,8 @@ func NewCmdAuthStatus() *cobra.Command {
GroupID: help.GROUP_AUTH.ID,
Run: func(cmd *cobra.Command, args []string) {
if err := runAuthStatus(cmd, options); err != nil {
log.Error().Err(err).Msg("Error retrieving authentication status")
exit.Error(pcio.Errorf("error retrieving authentication status: %w", err))
msg.FailMsg("Error retrieving authentication status: %s", err)
exit.Error().Err(err).Msg("Error retrieving authentication status")
}
},
}
Expand Down
8 changes: 2 additions & 6 deletions internal/pkg/cli/command/auth/whoami.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package auth
import (
"github.com/pinecone-io/cli/internal/pkg/utils/exit"
"github.com/pinecone-io/cli/internal/pkg/utils/help"
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/oauth"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/style"
"github.com/spf13/cobra"
)
Expand All @@ -23,9 +21,8 @@ func NewWhoAmICmd() *cobra.Command {

token, err := oauth.Token(cmd.Context())
if err != nil {
log.Error().Err(err).Msg("Error retrieving oauth token")
msg.FailMsg("Error retrieving oauth token: %s", err)
exit.Error(pcio.Errorf("error retrieving oauth token: %w", err))
exit.Error().Err(err).Msg("Error retrieving oauth token")
return
}
if token == nil || token.AccessToken == "" {
Expand All @@ -35,9 +32,8 @@ func NewWhoAmICmd() *cobra.Command {

claims, err := oauth.ParseClaimsUnverified(token)
if err != nil {
log.Error().Msg("Error parsing claims")
msg.FailMsg("An auth token was fetched but an error occurred while parsing the token's claims: %s", err)
exit.Error(pcio.Errorf("error parsing claims from access token: %s", err))
exit.Error().Err(err).Msg("An auth token was fetched but an error occurred while parsing the token's claims")
return
}
msg.InfoMsg("Logged in as " + style.Emphasis(claims.Email))
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/collection/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewCreateCollectionCmd() *cobra.Command {
collection, err := pc.CreateCollection(ctx, req)
if err != nil {
msg.FailMsg("Failed to create collection: %s\n", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to create collection")
}

if options.json {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/collection/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewDeleteCollectionCmd() *cobra.Command {
err := pc.DeleteCollection(ctx, options.name)
if err != nil {
msg.FailMsg("Failed to delete collection %s: %s\n", style.Emphasis(options.name), err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to delete collection")
}

msg.SuccessMsg("Collection %s deleted.\n", style.Emphasis(options.name))
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/collection/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewDescribeCollectionCmd() *cobra.Command {
collection, err := pc.DescribeCollection(ctx, options.name)
if err != nil {
msg.FailMsg("Failed to describe collection %s: %s\n", options.name, err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to describe collection")
}

if options.json {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/collection/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewListCollectionsCmd() *cobra.Command {
collections, err := pc.ListCollections(ctx)
if err != nil {
msg.FailMsg("Failed to list collections: %s\n", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to list collections")
}

// Sort results alphabetically by name
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/cli/command/config/set_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/pinecone-io/cli/internal/pkg/utils/log"
"github.com/pinecone-io/cli/internal/pkg/utils/msg"
"github.com/pinecone-io/cli/internal/pkg/utils/oauth"
"github.com/pinecone-io/cli/internal/pkg/utils/pcio"
"github.com/pinecone-io/cli/internal/pkg/utils/style"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -54,7 +53,7 @@ func NewSetEnvCmd() *cobra.Command {
if err != nil {
log.Error().Err(err).Msg("Error retrieving oauth token")
msg.FailMsg("Error retrieving oauth token: %s", err)
exit.Error(pcio.Errorf("error retrieving oauth token: %w", err))
exit.Error().Err(err).Msg("error retrieving oauth token")
}
if token != nil && (token.AccessToken != "" || token.RefreshToken != "") {
oauth.Logout()
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runConfigureIndexCmd(options configureIndexOptions) {
})
if err != nil {
msg.FailMsg("Failed to configure index %s: %+v\n", style.Emphasis(options.name), err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to configure index")
}
if options.json {
json := text.IndentJSON(idx)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func runCreateIndexCmd(options createIndexOptions) {
idx, err := runCreateIndexWithService(ctx, pc, options)
if err != nil {
msg.FailMsg("Failed to create index: %s\n", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to create index")
}

renderSuccessOutput(idx, options)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/create_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func runCreatePodCmd(options createPodOptions) {
idx, err := pc.CreatePodIndex(ctx, createRequest)
if err != nil {
msg.FailMsg("Failed to create index %s: %s\n", style.Emphasis(options.name), err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to create index")
}
if options.json {
json := text.IndentJSON(idx)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/create_serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func runCreateServerlessCmd(options createServerlessOptions) {
idx, err := pc.CreateServerlessIndex(ctx, createRequest)
if err != nil {
msg.FailMsg("Failed to create serverless index %s: %s\n", style.Emphasis(options.name), err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to create serverless index")
}
if options.json {
json := text.IndentJSON(idx)
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/cli/command/index/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ func NewDeleteCmd() *cobra.Command {
if err != nil {
if strings.Contains(err.Error(), "not found") {
msg.FailMsg("The index %s does not exist\n", style.Emphasis(options.name))
exit.Error().Err(err).Msgf("The index %s does not exist", style.Emphasis(options.name))
} else {
msg.FailMsg("Failed to delete index %s: %s\n", style.Emphasis(options.name), err)
exit.Error().Err(err).Msgf("Failed to delete index %s", style.Emphasis(options.name))
}
exit.Error(err)
}

msg.SuccessMsg("Index %s deleted.\n", style.Emphasis(options.name))
Expand Down
3 changes: 2 additions & 1 deletion internal/pkg/cli/command/index/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ func NewDescribeCmd() *cobra.Command {
if err != nil {
if strings.Contains(err.Error(), "not found") {
msg.FailMsg("The index %s does not exist\n", style.Emphasis(options.name))
exit.Error().Err(err).Msgf("The index %s does not exist", style.Emphasis(options.name))
} else {
msg.FailMsg("Failed to describe index %s: %s\n", style.Emphasis(options.name), err)
exit.Error().Err(err).Msgf("Failed to describe index %s", style.Emphasis(options.name))
}
exit.Error(err)
}

if options.json {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/index/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewListCmd() *cobra.Command {
idxs, err := pc.ListIndexes(ctx)
if err != nil {
msg.FailMsg("Failed to list indexes: %s\n", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to list indexes")
}

// Sort results alphabetically by name
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/cli/command/organization/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewDeleteOrganizationCmd() *cobra.Command {
org, err := ac.Organization.Describe(cmd.Context(), options.organizationID)
if err != nil {
msg.FailMsg("Failed to describe organization %s: %s\n", options.organizationID, err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to describe organization %s", style.Emphasis(options.organizationID))
}

if !options.skipConfirmation {
Expand All @@ -50,7 +50,7 @@ func NewDeleteOrganizationCmd() *cobra.Command {
err = ac.Organization.Delete(cmd.Context(), options.organizationID)
if err != nil {
msg.FailMsg("Failed to delete organization %s: %s\n", options.organizationID, err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to delete organization %s", style.Emphasis(options.organizationID))
}

// Clear target project if the deleted project is the target project
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/organization/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewDescribeOrganizationCmd() *cobra.Command {
org, err := ac.Organization.Describe(cmd.Context(), orgId)
if err != nil {
msg.FailMsg("Failed to describe organization %s: %s\n", orgId, err)
exit.Error(err)
exit.Error().Err(err).Msgf("Failed to describe organization %s", style.Emphasis(orgId))
}

if options.json {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/cli/command/organization/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewListOrganizationsCmd() *cobra.Command {
orgs, err := ac.Organization.List(cmd.Context())
if err != nil {
msg.FailMsg("Failed to list organizations: %s\n", err)
exit.Error(err)
exit.Error().Err(err).Msg("Failed to list organizations")
}

if options.json {
Expand Down
Loading
Loading