Skip to content

Commit f66910e

Browse files
committed
Fix CI failed
Fall back gracefully when querying the console cursor fails with an invalid handle, instead of raising an exception. Failed link: https://github.com/python/cpython/actions/runs/21563046527/job/62130029686?pr=144297
1 parent 460dfb3 commit f66910e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Lib/_pyrepl/windows_console.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,21 @@ def __write_changed_line(
274274
if wlen(newline) == self.width:
275275
info = CONSOLE_SCREEN_BUFFER_INFO()
276276
if not GetConsoleScreenBufferInfo(OutHandle, info):
277-
raise WinError(get_last_error())
278-
win_y = int(info.dwCursorPosition.Y - info.srWindow.Top)
279-
expected = y - self.__offset
280-
if win_y == expected + 1:
281-
# Terminal wrapped to next row.
282-
self.posxy = 0, y + 1
277+
err = get_last_error()
278+
if err == 6: # ERROR_INVALID_HANDLE
279+
# Best-effort fallback: cursor stays at end-of-line.
280+
self.posxy = self.width, y
281+
else:
282+
raise WinError(err)
283283
else:
284-
# Terminal did not wrap; cursor stays at end-of-line.
285-
self.posxy = self.width, y
284+
win_y = int(info.dwCursorPosition.Y - info.srWindow.Top)
285+
expected = y - self.__offset
286+
if win_y == expected + 1:
287+
# Terminal wrapped to next row.
288+
self.posxy = 0, y + 1
289+
else:
290+
# Terminal did not wrap; cursor stays at end-of-line.
291+
self.posxy = self.width, y
286292
else:
287293
self.posxy = wlen(newline), y
288294

0 commit comments

Comments
 (0)