From a1846d05798763cfeba922ec3b9ec9b9d76aebf8 Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Thu, 8 Aug 2024 14:26:33 +0200 Subject: [PATCH] Fix safe readlines: `AttributeError: 'NoneType' object has no attribute 'readlines'` (#5646) * fix * news * fix --------- Co-authored-by: a <1@1.1> --- news/fix_safe_readlines.rst | 23 +++++++++++++++++++++++ xonsh/procs/pipelines.py | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 news/fix_safe_readlines.rst diff --git a/news/fix_safe_readlines.rst b/news/fix_safe_readlines.rst new file mode 100644 index 000000000..fe4988298 --- /dev/null +++ b/news/fix_safe_readlines.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed exception "object has no attribute readlines" in case of redirect callable alias output. + +**Security:** + +* diff --git a/xonsh/procs/pipelines.py b/xonsh/procs/pipelines.py index eb136c64a..eec6c6c9e 100644 --- a/xonsh/procs/pipelines.py +++ b/xonsh/procs/pipelines.py @@ -62,6 +62,8 @@ def SIGNAL_MESSAGES(): def safe_readlines(handle, hint=-1): """Attempts to read lines without throwing an error.""" + if handle is None: + return [] try: lines = handle.readlines(hint) except OSError: @@ -276,7 +278,7 @@ class CommandPipeline: lines = b.splitlines(keepends=True) yield from lines self.end(tee_output=False) - elif self.captured == "stdout": + elif self.captured == "stdout" and stdout is not None: b = stdout.read() s = self._decode_uninew(b, universal_newlines=True) self.lines = s.splitlines(keepends=True)