| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "CliError.h" | ||
| 4 | |||
| 5 | #include <util/GlobalDefinitions.h> | ||
| 6 | |||
| 7 | namespace spice::compiler { | ||
| 8 | |||
| 9 | /** | ||
| 10 | * @param type Type of the error | ||
| 11 | * @param message Error message suffix | ||
| 12 | */ | ||
| 13 | ✗ | CliError::CliError(const CliErrorType &type, const std::string &message) { | |
| 14 | ✗ | errorMessage = "[Error|CLI] " + getMessagePrefix(type) + ": " + message; | |
| 15 | ✗ | } | |
| 16 | |||
| 17 | /** | ||
| 18 | * Get the message for this particular error instance | ||
| 19 | * | ||
| 20 | * @return Error message in form of a char array | ||
| 21 | */ | ||
| 22 | ✗ | const char *CliError::what() const noexcept { return errorMessage.c_str(); } | |
| 23 | |||
| 24 | /** | ||
| 25 | * Get the prefix of the error message for a particular error | ||
| 26 | * | ||
| 27 | * @param errorType Type of the error | ||
| 28 | * @return Prefix string for the error type | ||
| 29 | */ | ||
| 30 | ✗ | std::string CliError::getMessagePrefix(CliErrorType errorType) { | |
| 31 | ✗ | switch (errorType) { | |
| 32 | ✗ | case INCOMPLETE_TARGET_TRIPLE: | |
| 33 | ✗ | return "Incomplete target triple"; | |
| 34 | ✗ | case INVALID_TARGET_TRIPLE: | |
| 35 | ✗ | return "Invalid target triple"; | |
| 36 | ✗ | case SOURCE_FILE_MISSING: | |
| 37 | ✗ | return "Source file missing"; | |
| 38 | ✗ | case OPT_DEBUG_INFO_INCOMPATIBILITY: | |
| 39 | ✗ | return "Cannot emit debug info with optimization enabled"; | |
| 40 | ✗ | case NON_ZERO_EXIT_CODE: | |
| 41 | ✗ | return "Non-zero exit code"; | |
| 42 | ✗ | case FEATURE_NOT_SUPPORTED_FOR_TARGET: | |
| 43 | ✗ | return "Feature is not supported for this target"; | |
| 44 | ✗ | case FEATURE_NOT_SUPPORTED_WHEN_DOCKERIZED: | |
| 45 | ✗ | return "Feature not supported when dockerized"; | |
| 46 | ✗ | case INVALID_BUILD_MODE: | |
| 47 | ✗ | return "Invalid build mode"; | |
| 48 | ✗ | case COMING_SOON_CLI: | |
| 49 | ✗ | return "Coming soon"; | |
| 50 | } | ||
| 51 | − | assert_fail("Unknown error"); // GCOV_EXCL_LINE | |
| 52 | return "Unknown error"; // GCOV_EXCL_LINE | ||
| 53 | } | ||
| 54 | |||
| 55 | } // namespace spice::compiler | ||
| 56 |