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