Skip to content

Commit

Permalink
Show error message when data logger fails to write
Browse files Browse the repository at this point in the history
* I observed the benchmarks failing to write the output csv, but no
  error reported
* Now, an error is reported if it fails to write the data

Signed-off-by: Ryan Friedman <[email protected]>
  • Loading branch information
Ryanf55 committed Nov 29, 2024
1 parent bee8024 commit fece40c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions terrain_navigation/src/data_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#include <fstream>
#include <iostream>
#include <cstring>

DataLogger::DataLogger() {}

Expand All @@ -53,6 +54,10 @@ void DataLogger::writeToFile(const std::string path) {
std::cout << "[DataLogger] Writing data to file! " << path << std::endl;
std::ofstream output_file;
output_file.open(path, std::ios::trunc);
if (output_file.fail()) {
std::cerr << "[DataLogger]: Failed to write to file: " << path << " with error " << strerror(errno) << std::endl;
return;
}
if (print_header_) {
for (auto key : keys_) {
output_file << key << field_seperator;
Expand Down

0 comments on commit fece40c

Please sign in to comment.