diff --git a/cmd/coder/main.go b/cmd/coder/main.go index 5f2c0c9c..1147a87e 100644 --- a/cmd/coder/main.go +++ b/cmd/coder/main.go @@ -42,8 +42,6 @@ func main() { app.Version = fmt.Sprintf("%s %s %s/%s", version, runtime.Version(), runtime.GOOS, runtime.GOARCH) if err := app.ExecuteContext(ctx); err != nil { - // NOTE: The returned error is already handled and logged by the cmd lib (cobra), so no need to re-handle it here. - // As we are in the main, if there was an error, exit the process with an error code. - os.Exit(1) + flog.Fatal("%v", err) } } diff --git a/internal/cmd/ceapi.go b/internal/cmd/ceapi.go index 2da0dd25..e15b101d 100644 --- a/internal/cmd/ceapi.go +++ b/internal/cmd/ceapi.go @@ -2,11 +2,10 @@ package cmd import ( "context" + "fmt" "cdr.dev/coder-cli/coder-sdk" "golang.org/x/xerrors" - - "go.coder.com/flog" ) // Helpers for working with the Coder Enterprise API. @@ -73,7 +72,18 @@ func findEnv(ctx context.Context, client *coder.Client, envName, userEmail strin // Keep track of what we found for the logs. found = append(found, env.Name) } - flog.Error("found %q", found) - flog.Error("%q not found", envName) - return nil, coder.ErrNotFound + + return nil, notFoundButDidFind{ + needle: envName, + haystack: found, + } +} + +type notFoundButDidFind struct { + needle string + haystack []string +} + +func (n notFoundButDidFind) Error() string { + return fmt.Sprintf("\"%s\" not found in %q: %v", n.needle, n.haystack, coder.ErrNotFound) } diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 30bfa1ee..8917b22e 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -13,8 +13,10 @@ var verbose bool = false // Make constructs the "coder" root command func Make() *cobra.Command { app := &cobra.Command{ - Use: "coder", - Short: "coder provides a CLI for working with an existing Coder Enterprise installation", + Use: "coder", + Short: "coder provides a CLI for working with an existing Coder Enterprise installation", + SilenceErrors: true, + SilenceUsage: true, } app.AddCommand( diff --git a/internal/cmd/envs.go b/internal/cmd/envs.go index b67ab1a8..b18be8a6 100644 --- a/internal/cmd/envs.go +++ b/internal/cmd/envs.go @@ -111,7 +111,7 @@ coder envs --user charlie@coder.com ls -o json \ } if err = egroup.Wait(); err != nil { - return xerrors.Errorf("some stop operations failed: %w", err) + return xerrors.Errorf("some stop operations failed") } return nil }, diff --git a/internal/cmd/login.go b/internal/cmd/login.go index 857a1bb1..a1740b48 100644 --- a/internal/cmd/login.go +++ b/internal/cmd/login.go @@ -6,7 +6,6 @@ import ( "net" "net/http" "net/url" - "os" "strings" "cdr.dev/coder-cli/coder-sdk" @@ -42,10 +41,8 @@ func makeLoginCmd() *cobra.Command { // Don't return errors as it would print the usage. if err := login(cmd, u, config.URL, config.Session); err != nil { - flog.Error("Login error: %s.", err) - os.Exit(1) + return xerrors.Errorf("Login error", err) } - return nil }, } diff --git a/internal/cmd/shell.go b/internal/cmd/shell.go index 3f34075a..4e08edf0 100644 --- a/internal/cmd/shell.go +++ b/internal/cmd/shell.go @@ -71,7 +71,7 @@ func shell(_ *cobra.Command, cmdArgs []string) error { if exitErr, ok := err.(wsep.ExitError); ok { os.Exit(exitErr.Code) } - flog.Fatal("%+v", err) + return xerrors.Errorf("run command: %w", err) } return nil } @@ -153,7 +153,7 @@ func runCommand(ctx context.Context, envName, command string, args []string) err if err != nil { var closeErr websocket.CloseError if xerrors.As(err, &closeErr) { - return xerrors.Errorf("network error, is %q online? (%w)", envName, err) + return xerrors.Errorf("network error, is %q online?", envName) } return xerrors.Errorf("start remote command: %w", err) } diff --git a/internal/cmd/urls.go b/internal/cmd/urls.go index 7a3300fc..b79ddaa8 100644 --- a/internal/cmd/urls.go +++ b/internal/cmd/urls.go @@ -75,8 +75,7 @@ func validatePort(port string) (int, error) { } if p < 1 { // Port 0 means 'any free port', which we don't support. - flog.Error("Port must be > 0") - return 0, strconv.ErrRange + return 0, xerrors.New("Port must be > 0") } return int(p), nil }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: