mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
rpc: check fopen return code in dumptxoutset
This change improves the usability of the `dumptxoutset` RPC in two ways,
in the case that an invalid path is passed:
1. return from the RPC immediately, rather then when the file is first
tried to be written (which is _after_ calculating the UTXO set hash)
2. return a proper return code and error message instead of the cryptic
"CAutoFile::operator<<: file handle is nullptr: unspecified
iostream_category error" (-1)
This commit is contained in:
@@ -2281,6 +2281,12 @@ static RPCHelpMan dumptxoutset()
|
||||
|
||||
FILE* file{fsbridge::fopen(temppath, "wb")};
|
||||
CAutoFile afile{file, SER_DISK, CLIENT_VERSION};
|
||||
if (afile.IsNull()) {
|
||||
throw JSONRPCError(
|
||||
RPC_INVALID_PARAMETER,
|
||||
"Couldn't open file " + temppath.u8string() + " for writing.");
|
||||
}
|
||||
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
UniValue result = CreateUTXOSnapshot(
|
||||
node, node.chainman->ActiveChainstate(), afile, path, temppath);
|
||||
|
||||
Reference in New Issue
Block a user