mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpiutil] DataLogWriter: Don't crash on file open error (#7579)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user