From de635ac0a88a3bec230564e258c65fa2cfd5284b Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 3 Dec 2021 10:29:51 -0800 Subject: [PATCH] cmd/tailscale: print more detail in connection failure error message Before: failed to connect to local tailscaled (which appears to be running). Got error: Get "http://local-tailscaled.sock/localapi/v0/status": EOF After: failed to connect to local tailscaled (which appears to be running as IPNExtension, pid 2118). Got error: Get "http://local-tailscaled.sock/localapi/v0/status": EOF This was useful just now, as it made it clear that tailscaled I thought I was connecting to might not in fact be running; there was a second tailscaled running that made the error message slightly misleading. Signed-off-by: Josh Bleecher Snyder --- cmd/tailscale/cli/diag.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/tailscale/cli/diag.go b/cmd/tailscale/cli/diag.go index 10b302c83..5a09b1714 100644 --- a/cmd/tailscale/cli/diag.go +++ b/cmd/tailscale/cli/diag.go @@ -25,23 +25,23 @@ func fixTailscaledConnectError(origErr error) error { if err != nil { return fmt.Errorf("failed to connect to local Tailscaled process and failed to enumerate processes while looking for it") } - found := false + var foundProc ps.Process for _, proc := range procs { base := filepath.Base(proc.Executable()) if base == "tailscaled" { - found = true + foundProc = proc break } if runtime.GOOS == "darwin" && base == "IPNExtension" { - found = true + foundProc = proc break } if runtime.GOOS == "windows" && strings.EqualFold(base, "tailscaled.exe") { - found = true + foundProc = proc break } } - if !found { + if foundProc == nil { switch runtime.GOOS { case "windows": return fmt.Errorf("failed to connect to local tailscaled process; is the Tailscale service running?") @@ -52,5 +52,5 @@ func fixTailscaledConnectError(origErr error) error { } return fmt.Errorf("failed to connect to local tailscaled process; it doesn't appear to be running") } - return fmt.Errorf("failed to connect to local tailscaled (which appears to be running). Got error: %w", origErr) + return fmt.Errorf("failed to connect to local tailscaled (which appears to be running as %v, pid %v). Got error: %w", foundProc.Executable(), foundProc.Pid(), origErr) }