Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Silence cobra error handling and use flog.Fatal #134

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Silence cobra error handling and use flog.Fatal
  • Loading branch information
cmoog committed Oct 21, 2020
commit 3bee6d0673846301fd3aa3882adf5a70c76ef2e2
4 changes: 1 addition & 3 deletions cmd/coder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
5 changes: 1 addition & 4 deletions internal/cmd/ceapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

"cdr.dev/coder-cli/coder-sdk"
"golang.org/x/xerrors"

"go.coder.com/flog"
)

// Helpers for working with the Coder Enterprise API.
Expand Down Expand Up @@ -73,7 +71,6 @@ 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
}
6 changes: 4 additions & 2 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 1 addition & 4 deletions internal/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"

"cdr.dev/coder-cli/coder-sdk"
Expand Down Expand Up @@ -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
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down