Skip to content

Commit 3db477a

Browse files
committed
Prevent issues like #128066
1 parent da157dc commit 3db477a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/_pyrepl/readline.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,14 @@ def append_history_file(self, filename: str = gethistoryfile()) -> None:
464464
saved_length = self.get_history_length()
465465
length = self.get_current_history_length() - saved_length
466466
history = reader.get_trimmed_history(length)
467-
f = open(os.path.expanduser(filename), "a",
468-
encoding="utf-8", newline="\n")
467+
468+
try:
469+
f = open(os.path.expanduser(filename), "a",
470+
encoding="utf-8", newline="\n")
471+
except OSError as e:
472+
warnings.warn(f"failed to open the history file for writing: {e}")
473+
return
474+
469475
with f:
470476
for entry in history:
471477
entry = entry.replace("\n", "\r\n") # multiline history support

0 commit comments

Comments
 (0)