Skip to content

Commit 3efa764

Browse files
committed
Avoid the issue/pr recovery mechanism handling Ctrl-C keypress in prompts
Either InterruptErr or SilentErr will be present when the user has chosen "Cancel" or pressed Ctrl-C in prompts. We don't want the recovery mechanism to kick in these cases because the cancellation was likely willingly initiated by the user.
1 parent fff0514 commit 3efa764

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

pkg/cmd/issue/create/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ func createRun(opts *CreateOptions) (err error) {
249249

250250
if action == prShared.CancelAction {
251251
fmt.Fprintln(opts.IO.ErrOut, "Discarding.")
252-
err = nil // avoid triggering PreserveInput
253-
return cmdutil.SilentError
252+
err = cmdutil.SilentError
253+
return
254254
}
255255
} else {
256256
if tb.Title == "" {

pkg/cmd/pr/create/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ func createRun(opts *CreateOptions) (err error) {
299299

300300
if action == shared.CancelAction {
301301
fmt.Fprintln(opts.IO.ErrOut, "Discarding.")
302-
err = nil // avoid triggering PreserveInput
303-
return cmdutil.SilentError
302+
err = cmdutil.SilentError
303+
return
304304
}
305305

306306
err = handlePush(*opts, *ctx)

pkg/cmd/pr/shared/preserve.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ package shared
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"os"
78

9+
"github.com/AlecAivazis/survey/v2/terminal"
10+
"github.com/cli/cli/pkg/cmdutil"
811
"github.com/cli/cli/pkg/iostreams"
912
)
1013

@@ -18,6 +21,11 @@ func PreserveInput(io *iostreams.IOStreams, state *IssueMetadataState, createErr
1821
return
1922
}
2023

24+
if errors.Is(*createErr, cmdutil.SilentError) || errors.Is(*createErr, terminal.InterruptErr) {
25+
// these errors are user-initiated cancellations
26+
return
27+
}
28+
2129
out := io.ErrOut
2230

2331
// this extra newline guards against appending to the end of a survey line

0 commit comments

Comments
 (0)