@@ -11,6 +11,7 @@ import (
11
11
"golang.org/x/crypto/ssh/terminal"
12
12
"golang.org/x/sys/unix"
13
13
"golang.org/x/time/rate"
14
+ "golang.org/x/xerrors"
14
15
15
16
"go.coder.com/cli"
16
17
"go.coder.com/flog"
@@ -31,17 +32,17 @@ func (cmd *shellCmd) Spec() cli.CommandSpec {
31
32
}
32
33
}
33
34
34
- func enableTerminal (fd int ) (restore func ()) {
35
+ func enableTerminal (fd int ) (restore func (), err error ) {
35
36
state , err := terminal .MakeRaw (fd )
36
37
if err != nil {
37
- flog . Fatal ("make raw term: %v " , err )
38
+ return restore , xerrors . Errorf ("make raw term: %w " , err )
38
39
}
39
40
return func () {
40
41
err := terminal .Restore (fd , state )
41
42
if err != nil {
42
- flog .Fatal ("restore term state: %v" , err )
43
+ flog .Error ("restore term state: %v" , err )
43
44
}
44
- }
45
+ }, nil
45
46
}
46
47
47
48
func sendResizeEvents (termfd int , client * wush.Client ) {
@@ -90,11 +91,14 @@ func (cmd *shellCmd) Run(fl *pflag.FlagSet) {
90
91
args = []string {"-c" , "exec $(getent passwd $(whoami) | awk -F: '{ print $7 }')" }
91
92
}
92
93
93
- exitCode := runCommand (envName , command , args )
94
+ exitCode , err := runCommand (envName , command , args )
95
+ if err != nil {
96
+ flog .Fatal ("run command: %v" , err )
97
+ }
94
98
os .Exit (exitCode )
95
99
}
96
100
97
- func runCommand (envName string , command string , args []string ) int {
101
+ func runCommand (envName string , command string , args []string ) ( int , error ) {
98
102
var (
99
103
entClient = requireAuth ()
100
104
env = findEnv (entClient , envName )
@@ -104,7 +108,10 @@ func runCommand(envName string, command string, args []string) int {
104
108
105
109
tty := terminal .IsTerminal (termfd )
106
110
if tty {
107
- restore := enableTerminal (termfd )
111
+ restore , err := enableTerminal (termfd )
112
+ if err != nil {
113
+ return - 1 , err
114
+ }
108
115
defer restore ()
109
116
}
110
117
@@ -115,7 +122,7 @@ func runCommand(envName string, command string, args []string) int {
115
122
Stdin : true ,
116
123
}, command , args ... )
117
124
if err != nil {
118
- flog . Fatal ( "dial wush: %v" , err )
125
+ return - 1 , err
119
126
}
120
127
ctx := context .Background ()
121
128
@@ -133,8 +140,8 @@ func runCommand(envName string, command string, args []string) int {
133
140
134
141
exitCode , err := wc .Wait ()
135
142
if err != nil {
136
- flog . Fatal ( "wush error: %v" , err )
143
+ return - 1 , err
137
144
}
138
145
139
- return int (exitCode )
146
+ return int (exitCode ), nil
140
147
}
0 commit comments