From aec34ad6b30b2ee3fc19b8b7e0c6a3570235af4b Mon Sep 17 00:00:00 2001 From: Eddy Ashton Date: Thu, 4 Jul 2024 09:39:30 +0000 Subject: [PATCH] Cleaner error when we can't open a new snapshot file --- src/host/snapshots.h | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/host/snapshots.h b/src/host/snapshots.h index 585d679c2587..b1f8906d4ea7 100644 --- a/src/host/snapshots.h +++ b/src/host/snapshots.h @@ -270,17 +270,25 @@ namespace asynchost { std::ofstream snapshot_file( full_snapshot_path, std::ios::app | std::ios::binary); - const auto& snapshot = it->second.snapshot; - snapshot_file.write( - reinterpret_cast(snapshot->data()), - snapshot->size()); - snapshot_file.write( - reinterpret_cast(receipt_data), receipt_size); - - LOG_INFO_FMT( - "New snapshot file written to {} [{} bytes]", - file_name, - static_cast(snapshot_file.tellp())); + if (!snapshot_file.good()) + { + LOG_FAIL_FMT( + "Cannot write snapshot: error opening file {}", file_name); + } + else + { + const auto& snapshot = it->second.snapshot; + snapshot_file.write( + reinterpret_cast(snapshot->data()), + snapshot->size()); + snapshot_file.write( + reinterpret_cast(receipt_data), receipt_size); + + LOG_INFO_FMT( + "New snapshot file written to {} [{} bytes]", + file_name, + static_cast(snapshot_file.tellp())); + } } pending_snapshots.erase(it);