Skip to content

Commit e941352

Browse files
Copilotericcurtin
andcommitted
Address code review feedback: add safe type assertions
Co-authored-by: ericcurtin <1694275+ericcurtin@users.noreply.github.com>
1 parent 2045b93 commit e941352

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cmd/cli/readline/editor.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package readline
44

55
import (
6+
"fmt"
67
"os"
78
"os/exec"
89
"strings"
@@ -43,7 +44,10 @@ func OpenInEditor(fd uintptr, termios any, currentContent string) (string, error
4344
}
4445

4546
// Restore terminal to normal mode before launching editor
46-
t := termios.(*Termios)
47+
t, ok := termios.(*Termios)
48+
if !ok {
49+
return "", fmt.Errorf("invalid termios type")
50+
}
4751
if err := UnsetRawMode(fd, t); err != nil {
4852
return "", err
4953
}

cmd/cli/readline/editor_windows.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package readline
44

55
import (
6+
"fmt"
67
"os"
78
"os/exec"
89
"strings"
@@ -43,7 +44,11 @@ func OpenInEditor(fd uintptr, termios any, currentContent string) (string, error
4344
}
4445

4546
// Restore terminal to normal mode before launching editor
46-
if err := UnsetRawMode(fd, termios); err != nil {
47+
s, ok := termios.(*State)
48+
if !ok {
49+
return "", fmt.Errorf("invalid state type")
50+
}
51+
if err := UnsetRawMode(fd, s); err != nil {
4752
return "", err
4853
}
4954

0 commit comments

Comments
 (0)