Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle argument parsing errors gracefully #631

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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