Fixes #2029 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>main
parent
ede8ec1e20
commit
1cedd944cf
@ -0,0 +1,55 @@ |
||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build linux windows darwin
|
||||
|
||||
package cli |
||||
|
||||
import ( |
||||
"fmt" |
||||
"path/filepath" |
||||
"runtime" |
||||
"strings" |
||||
|
||||
ps "github.com/mitchellh/go-ps" |
||||
) |
||||
|
||||
// fixTailscaledConnectError is called when the local tailscaled has
|
||||
// been determined unreachable due to the provided origErr value. It
|
||||
// returns either the same error or a better one to help the user
|
||||
// understand why tailscaled isn't running for their platform.
|
||||
func fixTailscaledConnectError(origErr error) error { |
||||
procs, err := ps.Processes() |
||||
if err != nil { |
||||
return fmt.Errorf("failed to connect to local Tailscaled process and failed to enumerate processes while looking for it") |
||||
} |
||||
found := false |
||||
for _, proc := range procs { |
||||
base := filepath.Base(proc.Executable()) |
||||
if base == "tailscaled" { |
||||
found = true |
||||
break |
||||
} |
||||
if runtime.GOOS == "darwin" && base == "IPNExtension" { |
||||
found = true |
||||
break |
||||
} |
||||
if runtime.GOOS == "windows" && strings.EqualFold(base, "tailscaled.exe") { |
||||
found = true |
||||
break |
||||
} |
||||
} |
||||
if !found { |
||||
switch runtime.GOOS { |
||||
case "windows": |
||||
return fmt.Errorf("failed to connect to local tailscaled process; is the Tailscale service running?") |
||||
case "darwin": |
||||
return fmt.Errorf("failed to connect to local Tailscale service; is Tailscale running?") |
||||
case "linux": |
||||
return fmt.Errorf("failed to connect to local tailscaled; it doesn't appear to be running (sudo systemctl start tailscaled ?)") |
||||
} |
||||
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) |
||||
} |
||||
@ -0,0 +1,16 @@ |
||||
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !linux,!windows,!darwin
|
||||
|
||||
package cli |
||||
|
||||
import "fmt" |
||||
|
||||
// The github.com/mitchellh/go-ps package doesn't work on all platforms,
|
||||
// so just don't diagnose connect failures.
|
||||
|
||||
func fixTailscaledConnectError(origErr error) error { |
||||
return fmt.Errorf("failed to connect to local tailscaled process (is it running?); got: %w", origErr) |
||||
} |
||||
Loading…
Reference in new issue