Skip to content

Commit

Permalink
Removed catch and improve io error handling
Browse files Browse the repository at this point in the history
Signed-off-by: TaikiYamada4 <[email protected]>
  • Loading branch information
TaikiYamada4 committed Oct 28, 2024
1 parent c114991 commit fe9d19a
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions map/autoware_lanelet2_map_validator/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void process_requirements(

if (!validator_config.output_file_path.empty()) {
if (!std::filesystem::is_directory(validator_config.output_file_path)) {
throw std::runtime_error("Output path doesn't exist or is not a directory!");
throw std::invalid_argument("Output path doesn't exist or is not a directory!");
}
std::filesystem::path file_directory = validator_config.output_file_path;
std::filesystem::path file_path = file_directory / "lanelet2_validation_results.json";
Expand Down Expand Up @@ -161,25 +161,23 @@ int main(int argc, char * argv[])
}

Check warning on line 161 in map/autoware_lanelet2_map_validator/src/main.cpp

View check run for this annotation

Codecov / codecov/patch

map/autoware_lanelet2_map_validator/src/main.cpp#L161

Added line #L161 was not covered by tests

// Validation start
try {
if (meta_config.command_line_config.mapFile.empty()) {
throw std::runtime_error("No map file specified!");
} else if (!std::filesystem::is_regular_file(meta_config.command_line_config.mapFile)) {
throw std::runtime_error("Map file doesn't exist or is not a file!");
}
if (meta_config.command_line_config.mapFile.empty()) {
throw std::invalid_argument("No map file specified!");
} else if (!std::filesystem::is_regular_file(meta_config.command_line_config.mapFile)) {
throw std::invalid_argument("Map file doesn't exist or is not a file!");
}

if (!meta_config.requirements_file.empty()) {
std::ifstream input_file(meta_config.requirements_file);
json json_config;
input_file >> json_config;
process_requirements(json_config, meta_config);
} else {
auto issues = lanelet::autoware::validation::validateMap(meta_config);
lanelet::validation::printAllIssues(issues);
if (!meta_config.requirements_file.empty()) {
if (!std::filesystem::is_regular_file(meta_config.requirements_file)) {
throw std::invalid_argument("Input file doesn't exist or is not a file!");
}
} catch (const std::exception & e) {
std::cout << e.what() << std::endl;
return 1;
std::ifstream input_file(meta_config.requirements_file);
json json_config;
input_file >> json_config;
process_requirements(json_config, meta_config);
} else {

Check warning on line 178 in map/autoware_lanelet2_map_validator/src/main.cpp

View check run for this annotation

Codecov / codecov/patch

map/autoware_lanelet2_map_validator/src/main.cpp#L178

Added line #L178 was not covered by tests
auto issues = lanelet::autoware::validation::validateMap(meta_config);
lanelet::validation::printAllIssues(issues);
}

Check warning on line 181 in map/autoware_lanelet2_map_validator/src/main.cpp

View check run for this annotation

Codecov / codecov/patch

map/autoware_lanelet2_map_validator/src/main.cpp#L181

Added line #L181 was not covered by tests

return 0;
Expand Down

0 comments on commit fe9d19a

Please sign in to comment.