Skip to content

Commit

Permalink
handle arg parsing error gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
memchr committed Oct 21, 2024
1 parent e507877 commit 7b877e5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ int main(int argc, char *argv[]) {
spdlog::set_default_logger(spdlog::stderr_color_st("piper"));

RunConfig runConfig;
parseArgs(argc, argv, runConfig);
try {
parseArgs(argc, argv, runConfig);
} catch (const std::runtime_error& e) {
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}

#ifdef _WIN32
// Required on Windows to show IPA symbols
Expand Down Expand Up @@ -540,6 +545,10 @@ void parseArgs(int argc, char *argv[], RunConfig &runConfig) {
}
}

if (runConfig.modelPath.empty()) {
throw runtime_error("Model file is not provided");
}

// Verify model file exists
ifstream modelFile(runConfig.modelPath.c_str(), ios::binary);
if (!modelFile.good()) {
Expand Down

0 comments on commit 7b877e5

Please sign in to comment.