Skip to content

Commit

Permalink
Better error on attach no tty
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <[email protected]>
  • Loading branch information
John Howard committed May 25, 2016
1 parent 60abc96 commit f7541b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion api/client/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (cli *DockerCli) CheckTtyInput(attachStdin, ttyMode bool) error {
// be a tty itself: redirecting or piping the client standard input is
// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
if ttyMode && attachStdin && !cli.isTerminalIn {
return errors.New("cannot enable tty mode on non tty input")
eText := "the input device is not a TTY"
if runtime.GOOS == "windows" {
return errors.New(eText + ". If you are using mintty, try prefixing the command with 'winpty'")
}
return errors.New(eText)
}
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion integration-cli/docker_cli_attach_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os/exec"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -103,7 +104,10 @@ func (s *DockerSuite) TestAttachTTYWithoutStdin(c *check.C) {
return
}

expected := "cannot enable tty mode"
expected := "the input device is not a TTY"
if runtime.GOOS == "windows" {
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
}
if out, _, err := runCommandWithOutput(cmd); err == nil {
done <- fmt.Errorf("attach should have failed")
return
Expand Down
6 changes: 5 additions & 1 deletion integration-cli/docker_cli_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"reflect"
"runtime"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -182,7 +183,10 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
return
}

expected := "cannot enable tty mode"
expected := "the input device is not a TTY"
if runtime.GOOS == "windows" {
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
}
if out, _, err := runCommandWithOutput(cmd); err == nil {
errChan <- fmt.Errorf("exec should have failed")
return
Expand Down
8 changes: 6 additions & 2 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"runtime"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -2642,7 +2643,10 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) {
return
}

expected := "cannot enable tty mode"
expected := "the input device is not a TTY"
if runtime.GOOS == "windows" {
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
}
if out, _, err := runCommandWithOutput(cmd); err == nil {
errChan <- fmt.Errorf("run should have failed")
return
Expand All @@ -2655,7 +2659,7 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) {
select {
case err := <-errChan:
c.Assert(err, check.IsNil)
case <-time.After(6 * time.Second):
case <-time.After(30 * time.Second):
c.Fatal("container is running but should have failed")
}
}
Expand Down

0 comments on commit f7541b0

Please sign in to comment.