Skip to content

Commit

Permalink
[wpiutil] DataLogWriter: Don't crash on file open error (#7579)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson authored Dec 22, 2024
1 parent 469bb32 commit bb130b6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions wpiutil/src/main/native/cpp/DataLogWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@

using namespace wpi::log;

static std::unique_ptr<wpi::raw_ostream> CheckOpen(std::string_view filename,
std::error_code& ec) {
auto rv = std::make_unique<wpi::raw_fd_ostream>(filename, ec);
if (ec) {
return nullptr;
}
return rv;
}

DataLogWriter::DataLogWriter(std::string_view filename, std::error_code& ec,
std::string_view extraHeader)
: DataLogWriter{s_defaultMessageLog, filename, ec, extraHeader} {}

DataLogWriter::DataLogWriter(wpi::Logger& msglog, std::string_view filename,
std::error_code& ec, std::string_view extraHeader)
: DataLogWriter{msglog, std::make_unique<raw_fd_ostream>(filename, ec),
extraHeader} {
: DataLogWriter{msglog, CheckOpen(filename, ec), extraHeader} {
if (ec) {
Stop();
}
Expand Down

0 comments on commit bb130b6

Please sign in to comment.