7
7
"slices"
8
8
"strings"
9
9
10
+ "golang.org/x/xerrors"
11
+
10
12
"github.com/coder/coder/v2/cli/clibase"
11
13
"github.com/coder/coder/v2/cli/cliui"
12
14
"github.com/coder/coder/v2/cli/config"
@@ -60,7 +62,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
60
62
conf := r .createConfig ()
61
63
orgs , err := client .OrganizationsByUser (inv .Context (), codersdk .Me )
62
64
if err != nil {
63
- return fmt .Errorf ("failed to get organizations: %w" , err )
65
+ return xerrors .Errorf ("failed to get organizations: %w" , err )
64
66
}
65
67
// Keep the list of orgs sorted
66
68
slices .SortFunc (orgs , func (a , b codersdk.Organization ) int {
@@ -84,7 +86,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
84
86
if switchToOrg == "" {
85
87
err := conf .Organization ().Delete ()
86
88
if err != nil && ! errors .Is (err , os .ErrNotExist ) {
87
- return fmt .Errorf ("failed to unset organization: %w" , err )
89
+ return xerrors .Errorf ("failed to unset organization: %w" , err )
88
90
}
89
91
_ , _ = fmt .Fprintf (inv .Stdout , "Organization unset\n " )
90
92
} else {
@@ -107,7 +109,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
107
109
// Always write the uuid to the config file. Names can change.
108
110
err := conf .Organization ().Write (orgs [index ].ID .String ())
109
111
if err != nil {
110
- return fmt .Errorf ("failed to write organization to config file: %w" , err )
112
+ return xerrors .Errorf ("failed to write organization to config file: %w" , err )
111
113
}
112
114
}
113
115
@@ -123,7 +125,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
123
125
}
124
126
return sdkError
125
127
}
126
- return fmt .Errorf ("failed to get current organization: %w" , err )
128
+ return xerrors .Errorf ("failed to get current organization: %w" , err )
127
129
}
128
130
129
131
_ , _ = fmt .Fprintf (inv .Stdout , "Current organization context set to %s (%s)\n " , current .Name , current .ID .String ())
@@ -213,7 +215,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
213
215
typed , ok := data .([]codersdk.Organization )
214
216
if ! ok {
215
217
// This should never happen
216
- return "" , fmt .Errorf ("expected []Organization, got %T" , data )
218
+ return "" , xerrors .Errorf ("expected []Organization, got %T" , data )
217
219
}
218
220
return stringFormat (typed )
219
221
}),
@@ -250,7 +252,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
250
252
case "current" :
251
253
stringFormat = func (orgs []codersdk.Organization ) (string , error ) {
252
254
if len (orgs ) != 1 {
253
- return "" , fmt .Errorf ("expected 1 organization, got %d" , len (orgs ))
255
+ return "" , xerrors .Errorf ("expected 1 organization, got %d" , len (orgs ))
254
256
}
255
257
return fmt .Sprintf ("Current CLI Organization: %s (%s)\n " , orgs [0 ].Name , orgs [0 ].ID .String ()), nil
256
258
}
@@ -275,7 +277,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
275
277
default :
276
278
stringFormat = func (orgs []codersdk.Organization ) (string , error ) {
277
279
if len (orgs ) != 1 {
278
- return "" , fmt .Errorf ("expected 1 organization, got %d" , len (orgs ))
280
+ return "" , xerrors .Errorf ("expected 1 organization, got %d" , len (orgs ))
279
281
}
280
282
return fmt .Sprintf ("Organization: %s (%s)\n " , orgs [0 ].Name , orgs [0 ].ID .String ()), nil
281
283
}
0 commit comments