diff --git a/cmd/tailscale/cli/cli.go b/cmd/tailscale/cli/cli.go index 99d2d694f..87e127b9f 100644 --- a/cmd/tailscale/cli/cli.go +++ b/cmd/tailscale/cli/cli.go @@ -173,10 +173,17 @@ change in the future. } func fatalf(format string, a ...interface{}) { + if Fatalf != nil { + Fatalf(format, a...) + return + } log.SetFlags(0) log.Fatalf(format, a...) } +// Fatalf, if non-nil, is used instead of log.Fatalf. +var Fatalf func(format string, a ...interface{}) + var rootArgs struct { socket string } diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index 3eb8179f6..0d3d7e12b 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -174,7 +174,7 @@ func runDebug(ctx context.Context, args []string) error { if debugArgs.file == "get" { wfs, err := tailscale.WaitingFiles(ctx) if err != nil { - log.Fatal(err) + fatalf("%v\n", err) } e := json.NewEncoder(Stdout) e.SetIndent("", "\t") diff --git a/cmd/tailscale/cli/down.go b/cmd/tailscale/cli/down.go index 90c568bd0..30a2d2f9b 100644 --- a/cmd/tailscale/cli/down.go +++ b/cmd/tailscale/cli/down.go @@ -7,7 +7,6 @@ package cli import ( "context" "fmt" - "log" "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/client/tailscale" @@ -24,7 +23,7 @@ var downCmd = &ffcli.Command{ func runDown(ctx context.Context, args []string) error { if len(args) > 0 { - log.Fatalf("too many non-flag arguments: %q", args) + return fmt.Errorf("too many non-flag arguments: %q", args) } st, err := tailscale.Status(ctx) diff --git a/cmd/tailscale/cli/file.go b/cmd/tailscale/cli/file.go index 3c0b01a57..9f42c1d04 100644 --- a/cmd/tailscale/cli/file.go +++ b/cmd/tailscale/cli/file.go @@ -415,7 +415,7 @@ func waitForFile(ctx context.Context) error { fileWaiting := make(chan bool, 1) bc.SetNotifyCallback(func(n ipn.Notify) { if n.ErrMessage != nil { - log.Fatal(*n.ErrMessage) + fatalf("Notify.ErrMessage: %v\n", *n.ErrMessage) } if n.FilesWaiting != nil { select { diff --git a/cmd/tailscale/cli/logout.go b/cmd/tailscale/cli/logout.go index a58a0f1ba..3511b9efd 100644 --- a/cmd/tailscale/cli/logout.go +++ b/cmd/tailscale/cli/logout.go @@ -6,7 +6,7 @@ package cli import ( "context" - "log" + "fmt" "strings" "github.com/peterbourgon/ff/v3/ffcli" @@ -28,7 +28,7 @@ a reauthentication. func runLogout(ctx context.Context, args []string) error { if len(args) > 0 { - log.Fatalf("too many non-flag arguments: %q", args) + return fmt.Errorf("too many non-flag arguments: %q", args) } return tailscale.Logout(ctx) } diff --git a/cmd/tailscale/cli/netcheck.go b/cmd/tailscale/cli/netcheck.go index f0b33544e..59e8bc256 100644 --- a/cmd/tailscale/cli/netcheck.go +++ b/cmd/tailscale/cli/netcheck.go @@ -82,7 +82,7 @@ func runNetcheck(ctx context.Context, args []string) error { c.Logf("GetReport took %v; err=%v", d.Round(time.Millisecond), err) } if err != nil { - log.Fatalf("netcheck: %v", err) + return fmt.Errorf("netcheck: %w", err) } if err := printReport(dm, report); err != nil { return err diff --git a/cmd/tailscale/cli/ping.go b/cmd/tailscale/cli/ping.go index 8953ff09d..4dc9ee2a1 100644 --- a/cmd/tailscale/cli/ping.go +++ b/cmd/tailscale/cli/ping.go @@ -74,7 +74,7 @@ func runPing(ctx context.Context, args []string) error { prc := make(chan *ipnstate.PingResult, 1) bc.SetNotifyCallback(func(n ipn.Notify) { if n.ErrMessage != nil { - log.Fatal(*n.ErrMessage) + fatalf("Notify.ErrMessage: %v", *n.ErrMessage) } if pr := n.PingResult; pr != nil && pr.IP == ip { prc <- pr diff --git a/cmd/tailscale/cli/version.go b/cmd/tailscale/cli/version.go index 1726bac0b..9f3e17594 100644 --- a/cmd/tailscale/cli/version.go +++ b/cmd/tailscale/cli/version.go @@ -7,7 +7,7 @@ package cli import ( "context" "flag" - "log" + "fmt" "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/client/tailscale" @@ -32,7 +32,7 @@ var versionArgs struct { func runVersion(ctx context.Context, args []string) error { if len(args) > 0 { - log.Fatalf("too many non-flag arguments: %q", args) + return fmt.Errorf("too many non-flag arguments: %q", args) } if !versionArgs.daemon { outln(version.String()) diff --git a/cmd/tailscale/cli/web.go b/cmd/tailscale/cli/web.go index 003b5af39..399ad05e9 100644 --- a/cmd/tailscale/cli/web.go +++ b/cmd/tailscale/cli/web.go @@ -114,7 +114,7 @@ func tlsConfigFromEnvironment() *tls.Config { func runWeb(ctx context.Context, args []string) error { if len(args) > 0 { - log.Fatalf("too many non-flag arguments: %q", args) + return fmt.Errorf("too many non-flag arguments: %q", args) } if webArgs.cgi {