Skip to content

Commit

Permalink
Properly report truncate error in file::write
Browse files Browse the repository at this point in the history
  • Loading branch information
bugdea1er committed Jan 1, 2025
1 parent 4d6de6a commit 54a07ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@ std::string file::read() const {
}

void file::write(std::string_view content) const {
fs::resize_file(path(), 0);
std::error_code ec;
fs::resize_file(path(), 0, ec);
if (ec) {
throw fs::filesystem_error("Cannot write to a temporary file", ec);
}

append(content);
}

Expand Down

0 comments on commit 54a07ff

Please sign in to comment.