Skip to content

Commit 318aae1

Browse files
authored
better exit code handling -- fix error highlights to not cover SIGINT or SIGPIPE (#465)
* fix exitcode return to handle signals correctly -- use bash convention of 128 + signum. don't show red error mask for SIGINT or SIGPIPE * dont show left border for errors unless selected
1 parent 44535d2 commit 318aae1

5 files changed

Lines changed: 30 additions & 44 deletions

File tree

public/themes/default.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
--line-text-color: rgb(211, 215, 207);
157157
--line-svg-fill-color: rgb(150, 152, 150);
158158
--line-svg-hover-fill-color: #eceeec;
159-
--line-selected-border-color: rgb(193, 195, 193);
160159
--line-separator-color: rgb(126, 126, 126);
161160
--line-error-color: var(--app-error-color);
162161
--line-warning-color: var(--app-warning-color);

src/app/line/line.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969

7070
&.error-mask {
7171
background-color: var(--line-error-bg-color);
72-
border-left: 4px solid var(--line-error-border-left-color);
7372
}
7473
}
7574

src/app/line/linecomps.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ let heightLog = {};
5353

5454
dayjs.extend(localizedFormat);
5555

56-
function cmdHasError(cmd: Cmd): boolean {
57-
return cmd.getStatus() == "error" || cmd.getExitCode() != 0;
56+
function cmdShouldMarkError(cmd: Cmd): boolean {
57+
if (cmd.getStatus() == "error") {
58+
return true;
59+
}
60+
let exitCode = cmd.getExitCode();
61+
// 0, SIGINT, or SIGPIPE
62+
if (exitCode == 0 || exitCode == 130 || exitCode == 141) {
63+
return false;
64+
}
65+
return true;
5866
}
5967

6068
function getIsHidePrompt(line: LineType): boolean {
@@ -701,7 +709,7 @@ class LineCmd extends React.Component<
701709
)
702710
.get();
703711
const isRunning = cmd.isRunning();
704-
const cmdError = cmdHasError(cmd);
712+
const cmdError = cmdShouldMarkError(cmd);
705713
const mainDivCn = cn(
706714
"line",
707715
"line-cmd",

waveshell/pkg/packet/combined.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

waveshell/pkg/shexec/shexec.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,23 @@ func copyToCirFile(dest *cirfile.File, src io.Reader) error {
10691069
}
10701070
}
10711071

1072+
func GetCmdExitCode(cmd *exec.Cmd, err error) int {
1073+
if cmd == nil || cmd.ProcessState == nil {
1074+
return GetExitCode(err)
1075+
}
1076+
status, ok := cmd.ProcessState.Sys().(syscall.WaitStatus)
1077+
if !ok {
1078+
return cmd.ProcessState.ExitCode()
1079+
}
1080+
signaled := status.Signaled()
1081+
if signaled {
1082+
signal := status.Signal()
1083+
return 128 + int(signal)
1084+
}
1085+
exitStatus := status.ExitStatus()
1086+
return exitStatus
1087+
}
1088+
10721089
func GetExitCode(err error) int {
10731090
if err == nil {
10741091
return 0
@@ -1082,7 +1099,6 @@ func GetExitCode(err error) int {
10821099

10831100
func (c *ShExecType) ProcWait() error {
10841101
exitErr := c.Cmd.Wait()
1085-
base.Logf("procwait: %v\n", exitErr)
10861102
c.Lock.Lock()
10871103
c.Exited = true
10881104
c.Lock.Unlock()
@@ -1095,6 +1111,7 @@ func (c *ShExecType) IsExited() bool {
10951111
return c.Exited
10961112
}
10971113

1114+
// called in waveshell --single mode (returns the real cmddone packet)
10981115
func (c *ShExecType) WaitForCommand() *packet.CmdDonePacketType {
10991116
donePacket := packet.MakeCmdDonePacket(c.CK)
11001117
exitErr := c.ProcWait()
@@ -1116,7 +1133,7 @@ func (c *ShExecType) WaitForCommand() *packet.CmdDonePacketType {
11161133
endTs := time.Now()
11171134
cmdDuration := endTs.Sub(c.StartTs)
11181135
donePacket.Ts = endTs.UnixMilli()
1119-
donePacket.ExitCode = GetExitCode(exitErr)
1136+
donePacket.ExitCode = GetCmdExitCode(c.Cmd, exitErr)
11201137
donePacket.DurationMs = int64(cmdDuration / time.Millisecond)
11211138
if c.FileNames != nil {
11221139
os.Remove(c.FileNames.StdinFifo) // best effort (no need to check error)

0 commit comments

Comments
 (0)