-
Notifications
You must be signed in to change notification settings - Fork 37.7k
util: Show descriptive error messages when FileCommit fails #26654
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
util: Show descriptive error messages when FileCommit fails #26654
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
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.
Somewhat unrelated, but after this change, how often are we using the
#ifdef WIN32
if (strerror_s(...
case in SysErrorString
? Wondering if we can (in general) further consolidate this error logging.
src/util/sock.cpp
Outdated
@@ -419,18 +419,7 @@ void Sock::Close() | |||
#ifdef WIN32 |
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.
Could turn this into:
#ifdef WIN32 | |
std::string NetworkErrorString(int err) | |
{ | |
#ifdef WIN32 | |
return Win32ErrorString(err); | |
#else | |
// On BSD sockets implementations, NetworkErrorString is the same as SysErrorString. | |
return SysErrorString(err); | |
#endif | |
} |
@fanquake Great suggestions, thanks. Will incorporate them all shortly.
I don't think in many places. In addition to the potential use of it for Line 164 in 3eaf7be
If I artificially trigger that using the current code (by giving it an impossible path), it shows: If I substitute it with Since the error codes are unrelated ( Potentially, we could have a |
Concept ACK. |
@john-moffett please rebase? |
Thanks for reminding me! Will rebase tomorrow. |
0ded69f
to
3883afe
Compare
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.
nice. lgtm, but I didn't look at the windows stuff
src/util/fs_helpers.cpp
Outdated
return false; | ||
} | ||
#else | ||
if (fsync(fileno(file)) != 0 && errno != EINVAL) { | ||
LogPrintf("%s: fsync failed: %d\n", __func__, errno); | ||
LogPrintf("%s: fsync failed: %d\n", __func__, SysErrorString(errno)); |
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.
LogPrintf("%s: fsync failed: %d\n", __func__, SysErrorString(errno)); | |
LogPrintf("fsync failed: %s\n", SysErrorString(errno)); |
nits:
- Can remove the manual func logging, which isn't needed, because all strings in this function are already unique to the codebase. Also, users can enable the setting which enables function logging, if they want this.
- Can change
%d
to%s
, since it is a string. (No behavior difference though)
Only raw errno codes are logged if FileCommit fails. These are implementation-specific, so it makes it harder to debug based on user reports. Instead, use SysErrorString to display both the raw int value and the descriptive message.
GetErrorReason()'s Win32 implementation does the same thing as Win32ErrorString(int err) from syserror.cpp, so call the latter. Also remove now-unnecessary headers from sock.cpp and less verbose handling of #ifdefs.
3883afe
to
5408a55
Compare
CI can be ignored. lgtm ACK 5408a55 💡 Show signatureSignature:
|
Only raw
errno
int values are logged ifFileCommit
fails. These values are implementation-specific, so it makes it harder to debug based on user reports. For instance, #26455 (comment) and another.Instead, use
SysErrorString
(or the refactored Windows equivalentWin32ErrorString
) to display both the raw int value and the descriptive message. All other instances in the code I could find whereerrno
or (Windows-only)GetLastError()
/WSAGetLastError()
are logged use the full descriptive string. For example:bitcoin/src/util/sock.cpp
Line 390 in 1b68094
bitcoin/src/util/sock.cpp
Line 272 in 1b68094
bitcoin/src/netbase.cpp
Lines 515 to 516 in 7e1007a
bitcoin/src/init.cpp
Line 164 in 8ccab65
I refactored the Windows formatting code to put it in
syserror.cpp
, as it's applicable to all Win32 API system errors, not just networking errors. To be clear, the Windows API functionsWSAGetLastError()
andGetLastError()
are currently equivalent.