Skip to content

Commit

Permalink
Print to cerr instead of throwing exception to quit
Browse files Browse the repository at this point in the history
  • Loading branch information
CrushedPixel committed Oct 11, 2024
1 parent e9c416d commit ba7dc95
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cli/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ bool is_valid_au_manufacturer_code(const std::string& code)
[](unsigned char c) { return std::islower(c) || std::isdigit(c); });
}

void error_exit(const std::string& msg, int code = 1)
{
std::cerr << msg << std::endl;
exit(code);
}

int main(int argc, char** argv)
{
CLI::App app{"CLAP Wrapper CLI"};
Expand Down Expand Up @@ -188,25 +194,25 @@ int main(int argc, char** argv)
{
if (au_manufacturer_code.empty() != au_manufacturer_name.empty())
{
throw std::runtime_error("Both AU manufacturer code and name must be set if one is provided");
error_exit("Both AU manufacturer code and name must be set if one is provided");
}
if (!au_manufacturer_code.empty() && !is_valid_au_manufacturer_code(au_manufacturer_code))
{
throw std::runtime_error(
error_exit(
"AU manufacturer code must be exactly 4 characters long, and start with an uppercase letter "
"followed only by lowercase letters and/or numbers");
}
}
#else
if (build_au)
{
throw std::runtime_error("AU output format is only supported on macOS");
error_exit("AU output format is only supported on macOS");
}
#endif

if (!build_au && !build_vst3)
{
throw std::runtime_error("At least one output format must be specified");
error_exit("At least one output format must be specified");
}

// convert paths away from raw strings
Expand All @@ -228,7 +234,7 @@ int main(int argc, char** argv)
write_cmakelists(build_dir);

// extract project name from input path
auto project_name = sanitize_cmake_identifier(input_path.stem());
auto project_name = sanitize_cmake_identifier(input_path.stem().u8string());

// construct cmake command with variables supplied
std::string cmake_cmd = fmt::format(
Expand Down Expand Up @@ -324,7 +330,7 @@ int main(int argc, char** argv)
}
catch (const std::exception& e)
{
std::cerr << "Error during wrapping: " << e.what() << std::endl;
error_exit("Error during wrapping: " + std::string(e.what()));
return 1;
}

Expand Down

0 comments on commit ba7dc95

Please sign in to comment.