New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-39468: Improve the site module's error handling while writing .python_history #18299
base: main
Are you sure you want to change the base?
Conversation
I'd title it "errno not returned for some errors in write_history, append_history, and history_truncate_file". In particular these calls return -1 when the internal if (rv == 0 && histname && tempname)
rv = histfile_restore (tempname, histname);
if (rv != 0)
{
if (tempname)
unlink (tempname);
history_lines_written_to_file = 0;
}This needs a simple fix to update the value of if (rv == 0 && histname && tempname)
rv = histfile_restore (tempname, histname);
if (rv != 0) {
rv = errno;
if (tempname)
unlink(tempname);
history_lines_written_to_file = 0;
} |
Codecov Report
@@ Coverage Diff @@
## master #18299 +/- ##
==========================================
- Coverage 82.20% 82.12% -0.08%
==========================================
Files 1957 1954 -3
Lines 589079 583367 -5712
Branches 44401 44401
==========================================
- Hits 484247 479093 -5154
+ Misses 95174 94636 -538
+ Partials 9658 9638 -20
Continue to review full report at Codecov.
|
|
I still want to notice the users that the .python_history file is not writable, so that they wouldn't guess there's something wrong somewhere else. |
| # https://bugs.python.org/issue19891 | ||
| pass | ||
| elif isinstance(e, (OSError)) and e.errno == -1: | ||
| print("Warning: unable to write into .python_history") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use two except clauses:
except (FileNotFoundError, PermissionError):
pass
except OsError:
if e.errno == -1:
print(...)
else:
raise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, are you sure that printing to stdout is the right thing to do here?
|
I am getting an error trying to check out this branch: My GH clone is up to date with cpython and my local repro is up to date with my clone. |
https://bugs.python.org/issue39468