Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in EOF handling that was causing files to hang after the last command. The issue was traced back to commit 9a8018e and relates to how the shell processes end-of-file conditions during input reading.
Key Changes
- Improved EOF handling logic in the shell's main read loop
- Separated read error handling from command evaluation error handling
- Added explicit check to break the loop when EOF is encountered
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| err := s.evalLine(line) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if readErr == io.EOF { | ||
| break | ||
| } |
There was a problem hiding this comment.
When readErr is io.EOF, the code still calls s.evalLine(line) before checking for EOF. If the last line doesn't end with a newline, line will contain the partial content and should be processed. However, if ReadString returns an empty line with EOF, this could lead to evaluating an empty command. Consider checking if line is non-empty or if it contains meaningful content before evaluation when EOF is encountered.
| err := s.evalLine(line) | |
| if err != nil { | |
| return err | |
| } | |
| if readErr == io.EOF { | |
| break | |
| } | |
| // Only evaluate non-empty lines at EOF | |
| if readErr == io.EOF { | |
| if strings.TrimSpace(line) != "" { | |
| err := s.evalLine(line) | |
| if err != nil { | |
| return err | |
| } | |
| } | |
| break | |
| } | |
| err := s.evalLine(line) | |
| if err != nil { | |
| return err | |
| } |
|
thank you for your contribution! |
While trying to fix #29, some files were hanging after the last command and took me while to figure out why.
Following the rabbit hole I found out it had to do with
9a8018e.The changes are tested.