Skip to content

Commit

Permalink
Improved exceptions when a file path containing invalid characters is…
Browse files Browse the repository at this point in the history
… provided.

On Windows (under visual studio) if a std::filesystem::path contains ':', extension() returns empty string.

There's not an obvious method within std::filesystem to check a path for bad characters.
  • Loading branch information
Robadob committed Oct 28, 2024
1 parent 12e5582 commit 055e348
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion include/flamegpu/io/LoggerFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ class LoggerFactory {
return std::make_unique<XMLLogger>(output_path, prettyPrint, truncateFile);
} else if (extension == ".json") {
return std::make_unique<JSONLogger>(output_path, prettyPrint, truncateFile);
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in LoggerFactory::createLogger().", output_path.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be written "
"by StateWriterFactory::createLogger().",
"by LoggerFactory::createLogger().",
output_path.c_str());
}
};
Expand Down
3 changes: 3 additions & 0 deletions include/flamegpu/io/StateReaderFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class StateReaderFactory {
return new XMLStateReader();
} else if (extension == ".json") {
return new JSONStateReader();
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in StateReaderFactory::createLogger().", input.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be read "
"by StateReaderFactory::createReader().",
Expand Down
3 changes: 3 additions & 0 deletions include/flamegpu/io/StateWriterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class StateWriterFactory {
return new XMLStateWriter();
} else if (extension == ".json") {
return new JSONStateWriter();
} else if (extension.empty()) {
THROW exception::InvalidFilePath("Filepath '%s' contains unsuitable characters or lacks a file extension, "
"in StateWriterFactory::createLogger().", output_file.c_str());
}
THROW exception::UnsupportedFileType("File '%s' is not a type which can be written "
"by StateWriterFactory::createWriter().",
Expand Down

0 comments on commit 055e348

Please sign in to comment.