Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add suggestion if tunnel address is in use #515

Merged
merged 1 commit into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions util/display/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,13 @@ func BadPortType(protocol string) {
--------------------------------------------------------------------------------
`, protocol))
}

func PortInUse(port string) {
os.Stderr.WriteString(fmt.Sprintf(`
--------------------------------------------------------------------------------
ADDRESS IN USE
It appears your local port (%s) is in use. Please specify a different port with
the '-p' flag. (eg. 'nanobox tunnel data.db -p 5444')
--------------------------------------------------------------------------------
`, port))
}
15 changes: 12 additions & 3 deletions util/nanoagent/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"io"
"net"
"net/http"
"strings"
"syscall"

"github.com/nanobox-io/nanobox/util"
"github.com/nanobox-io/nanobox/util/display"
)

Expand All @@ -29,10 +31,17 @@ func Tunnel(key, location, port, name string) error {
// setup a tcp listener
serv, err := net.Listen("tcp4", fmt.Sprintf(":%s", port))
if err != nil {
if err == syscall.EADDRINUSE {
return fmt.Errorf("it appears your local port (%s) is in use please specify a different port", port)
err2 := util.Err{
Code: "TUNNEL",
Message: err.Error(),
}
return fmt.Errorf("failed to setup tcp listener: %s", err.Error())
if strings.Contains(err.Error(), "address already in use") || err == syscall.EADDRINUSE {
display.PortInUse(port)
err2.Code = "USER"
err2.Suggest = fmt.Sprintf("It appears your local port (%s) is in use. Please specify a different port.", port)
}

return util.ErrorAppend(err2, "failed to setup tcp listener")
}

display.TunnelEstablished(name, port)
Expand Down