[ BugFix ] Handle Failed Terminal Read Gracefully #164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In
Terminal::read()
if the result offread(STDIN)
isfalse
, indicating an error, we return an empty string.This can be a problem. While this issue is rare, it does appear to be temporary (maybe some sort of race condition?)
The problem is that
Concerns/TypedValue::trackTypedValue()
expects the string$key
passed to the 'on key' listener to not be empty as it expects to be able to read$key[0]
. By checking that$key
is not empty we can eliminate a repeatedE_WARNING: Uninitialized string offset 0
from overwhelming the terminal output when encountered inside of a loop.I've also added a safeguard in the prompt looping mechanism to
continue
onto the next iteration if this is encountered.I haven't found a good way to make a test actually fail when a warning is encountered, but this configuration change shows the warning pretty clearly. And at least it is covered by a test, even if it's not returning a non-zero exitcode.