From ba2c52dd39ffa67cc26202b1d8eaec9f7c770b36 Mon Sep 17 00:00:00 2001 From: MoAlyousef Date: Fri, 27 Nov 2020 14:48:15 +0300 Subject: [PATCH] unify error messages --- src/build.cpp | 2 +- src/cmake.cpp | 2 +- src/gen.cpp | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/build.cpp b/src/build.cpp index eedd407..8483ae0 100644 --- a/src/build.cpp +++ b/src/build.cpp @@ -25,7 +25,7 @@ int run(int argc, char **argv) { if (!fs::exists("CMakeLists.txt")) if (gen::generate_cmake(".")) - throw std::runtime_error("CMake generation failure!"); + throw std::runtime_error("[cmkr] error: CMake generation failure!"); ss << "cmake -S. -B" << cmake.bin_dir << " "; diff --git a/src/cmake.cpp b/src/cmake.cpp index 990db9d..0250609 100644 --- a/src/cmake.cpp +++ b/src/cmake.cpp @@ -21,7 +21,7 @@ std::vector to_string_vec( CMake::CMake(const std::string &path, bool build) { if (!fs::exists(fs::path(path) / "cmake.toml")) { - throw std::runtime_error("No cmake.toml was found!"); + throw std::runtime_error("[cmkr] error: No cmake.toml was found!"); } const auto toml = toml::parse((fs::path(path) / "cmake.toml").string()); if (build) { diff --git a/src/gen.cpp b/src/gen.cpp index 2375036..40045c1 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -33,7 +33,7 @@ std::string format(const char *fmt, Args... args) { char *buf = new char[sz]; int ret = snprintf(buf, sz, fmt, args...); if (ret != sz - 1) - throw std::runtime_error("Error formatting string!"); + throw std::runtime_error("[cmkr] error: Error formatting string!"); std::string temp(buf, buf + sz - 1); delete[] buf; return temp; @@ -80,7 +80,7 @@ int generate_project(const char *str) { dest = "include/" + dir_name; } else { throw std::runtime_error( - "Unknown project type. Types are exe, lib, shared, static, interface!"); + "[cmkr] error: Unknown project type. Types are exe, lib, shared, static, interface!"); } const auto tomlbuf = detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str, @@ -257,7 +257,7 @@ int generate_cmake(const char *path) { add_command = "add_library"; } else { throw std::runtime_error( - "Unknown binary type! Supported types are exe, shared and static"); + "[cmkr] error: Unknown binary type! Supported types are exe, lib, shared, static, interface"); } if (!bin.sources.empty()) { @@ -391,6 +391,8 @@ int generate_cmake(const char *path) { if (fs::exists(fs::path(sub) / "cmake.toml")) generate_cmake(sub.c_str()); } + } else { + throw std::runtime_error("[cmkr] error: No cmake.toml found!"); } return 0; }