Skip to content

Commit 578b9ff

Browse files
authored
fix: enrich the notLoggedInMessage error message with the full path to the coder (#17715)
--------- Signed-off-by: Callum Styan <callumstyan@gmail.com>
1 parent 15bd7a3 commit 578b9ff

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

cli/logout_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli_test
22

33
import (
4+
"fmt"
45
"os"
56
"runtime"
67
"testing"
@@ -89,10 +90,14 @@ func TestLogout(t *testing.T) {
8990
logout.Stdin = pty.Input()
9091
logout.Stdout = pty.Output()
9192

93+
executable, err := os.Executable()
94+
require.NoError(t, err)
95+
require.NotEqual(t, "", executable)
96+
9297
go func() {
9398
defer close(logoutChan)
94-
err := logout.Run()
95-
assert.ErrorContains(t, err, "You are not logged in. Try logging in using 'coder login <url>'.")
99+
err = logout.Run()
100+
assert.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
96101
}()
97102

98103
<-logoutChan

cli/root.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const (
7272
varDisableDirect = "disable-direct-connections"
7373
varDisableNetworkTelemetry = "disable-network-telemetry"
7474

75-
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
75+
notLoggedInMessage = "You are not logged in. Try logging in using '%s login <url>'."
7676

7777
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
7878
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
@@ -534,7 +534,11 @@ func (r *RootCmd) InitClient(client *codersdk.Client) serpent.MiddlewareFunc {
534534
rawURL, err := conf.URL().Read()
535535
// If the configuration files are absent, the user is logged out
536536
if os.IsNotExist(err) {
537-
return xerrors.New(notLoggedInMessage)
537+
binPath, err := os.Executable()
538+
if err != nil {
539+
binPath = "coder"
540+
}
541+
return xerrors.Errorf(notLoggedInMessage, binPath)
538542
}
539543
if err != nil {
540544
return err

cli/userlist_test.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"fmt"
8+
"os"
79
"testing"
810

911
"github.com/stretchr/testify/assert"
@@ -69,9 +71,12 @@ func TestUserList(t *testing.T) {
6971
t.Run("NoURLFileErrorHasHelperText", func(t *testing.T) {
7072
t.Parallel()
7173

74+
executable, err := os.Executable()
75+
require.NoError(t, err)
76+
7277
inv, _ := clitest.New(t, "users", "list")
73-
err := inv.Run()
74-
require.Contains(t, err.Error(), "Try logging in using 'coder login <url>'.")
78+
err = inv.Run()
79+
require.Contains(t, err.Error(), fmt.Sprintf("Try logging in using '%s login <url>'.", executable))
7580
})
7681
t.Run("SessionAuthErrorHasHelperText", func(t *testing.T) {
7782
t.Parallel()

0 commit comments

Comments
 (0)