Skip to content

Commit 33ecfd5

Browse files
committed
Write credstore warning to stderr to preserve structured output
1 parent d9a64a3 commit 33ecfd5

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

internal/commands/signup.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,11 @@ func saveSignupConfig(token, account, apiURL string) error {
740740
globalCfg := config.LoadGlobal()
741741

742742
if creds != nil {
743-
if err := credsSaveToken(token); err == nil {
744-
globalCfg.Token = ""
745-
} else {
743+
if err := credsSaveToken(token); err != nil {
744+
fmt.Fprintf(os.Stderr, "Warning: could not save token to credential store: %v\n", err)
746745
globalCfg.Token = token
746+
} else {
747+
globalCfg.Token = ""
747748
}
748749
} else {
749750
globalCfg.Token = token

internal/commands/signup_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,29 @@ func TestGetCookieValue(t *testing.T) {
716716
})
717717
}
718718

719+
func TestSignupCompleteRejectsEmptyToken(t *testing.T) {
720+
t.Run("rejects empty session token", func(t *testing.T) {
721+
resetSignupFlags()
722+
server := newTestSignupServer(t, testSignupServerOpts{accessToken: "fizzy_test"})
723+
defer server.Close()
724+
725+
mock := NewMockClient()
726+
SetTestMode(mock)
727+
SetTestConfig("", "", server.URL)
728+
defer ResetTestMode()
729+
730+
restoreStdin := pipeSessionToken("")
731+
defer restoreStdin()
732+
733+
signupCompleteCmd.Flags().Set("account", "123456")
734+
err := signupCompleteCmd.RunE(signupCompleteCmd, []string{})
735+
736+
if err == nil {
737+
t.Error("expected error for empty session token")
738+
}
739+
})
740+
}
741+
719742
func TestReadSessionTokenFromStdin(t *testing.T) {
720743
t.Run("reads token from piped stdin", func(t *testing.T) {
721744
restoreStdin := pipeSessionToken("eyJ-session-token-value")

0 commit comments

Comments
 (0)