Skip to content

Commit 8f9e346

Browse files
committed
better error msg
1 parent aec290e commit 8f9e346

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

internal/shell_executable/shell_executable.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,38 @@ func (b *ShellExecutable) VTBellChannel() chan bool {
104104
func (b *ShellExecutable) ReadUntilConditionOrTimeout(condition func() bool, timeout time.Duration) error {
105105
err := b.ptyReader.ReadUntilConditionOrTimeout(condition, timeout)
106106
if err != nil {
107-
return wrapReaderError(err)
108-
}
107+
// First log any remaining output
108+
state := b.vt.GetScreenState()
109+
for _, row := range state {
110+
output := virtual_terminal.BuildCleanedRow(row)
111+
if len(output) > 0 {
112+
b.programLogger.Plainln(output)
113+
}
114+
}
109115

116+
// Then return error message
117+
if errors.Is(err, io.EOF) || errors.Is(err, syscall.EIO) {
118+
return ErrProgramExited
119+
}
120+
if errors.Is(err, condition_reader.ErrConditionNotMet) {
121+
return fmt.Errorf("the 'exit' command should terminate your shell, but your shell is still running")
122+
}
123+
return err
124+
}
110125
return nil
111126
}
112127

128+
func (b *ShellExecutable) LogRemainingOutput() {
129+
// Get any remaining output from the virtual terminal
130+
state := b.vt.GetScreenState()
131+
for _, row := range state {
132+
output := virtual_terminal.BuildCleanedRow(row)
133+
if len(output) > 0 {
134+
b.LogOutput([]byte(output))
135+
}
136+
}
137+
}
138+
113139
func (b *ShellExecutable) SendCommand(command string) error {
114140
if err := b.SendCommandRaw(command + "\n"); err != nil {
115141
return err

internal/stage4.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func testExit(stageHarness *test_case_harness.TestCaseHarness) error {
4949
return fmt.Errorf("Expected program to exit with 0 exit code, program is still running.")
5050
} else {
5151
// TODO: Other than ErrProgramExited, what other errors could we get? Are they user errors or internal errors?
52-
return fmt.Errorf("Error reading output: %v", readErr)
52+
return fmt.Errorf("Error: %v", readErr)
5353
}
5454
}
5555

0 commit comments

Comments
 (0)