exception/linker-error.spice
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | // Std imports | ||
| 4 | import "std/text/stringstream"; | ||
| 5 | |||
| 6 | public type LinkerErrorType enum { | ||
| 7 | LINKER_INVOKER_NOT_FOUND, | ||
| 8 | LINKER_NOT_FOUND, | ||
| 9 | ARCHIVER_NOT_FOUND, | ||
| 10 | LINKER_ERROR, | ||
| 11 | SANITIZER_NOT_SUPPORTED_BY_LINKER_INVOKER | ||
| 12 | } | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Custom exception for errors, occurring when linking the output executable | ||
| 16 | */ | ||
| 17 | ✗ | public type LinkerError struct { | |
| 18 | String errorMessage | ||
| 19 | } | ||
| 20 | |||
| 21 | /** | ||
| 22 | * @param type Type of the error | ||
| 23 | * @param message Error message suffix | ||
| 24 | */ | ||
| 25 | ✗ | public p LinkerError.ctor(const LinkerErrorType errorType, const string message) { | |
| 26 | ✗ | StringStream msg; | |
| 27 | ✗ | msg << "[Error|Linker] " << this.getMessagePrefix(errorType) << ": " << message; | |
| 28 | ✗ | this.errorMessage = msg.str(); | |
| 29 | ✗ | } | |
| 30 | |||
| 31 | /** | ||
| 32 | * Get the message for this particular error instance | ||
| 33 | * | ||
| 34 | * @return Error message | ||
| 35 | */ | ||
| 36 | ✗ | public f<const String&> LinkerError.getMessage() { | |
| 37 | ✗ | return this.errorMessage; | |
| 38 | } | ||
| 39 | |||
| 40 | /** | ||
| 41 | * Get the prefix of the error message for a particular error | ||
| 42 | * | ||
| 43 | * @param errorType Type of the error | ||
| 44 | * @return Prefix string for the error type | ||
| 45 | */ | ||
| 46 | ✗ | f<string> LinkerError.getMessagePrefix(const LinkerErrorType errorType) { | |
| 47 | ✗ | switch errorType { | |
| 48 | ✗ | case LinkerErrorType::LINKER_INVOKER_NOT_FOUND: { return "Linker invoker not found"; } | |
| 49 | ✗ | case LinkerErrorType::LINKER_NOT_FOUND: { return "Linker not found"; } | |
| 50 | ✗ | case LinkerErrorType::ARCHIVER_NOT_FOUND: { return "Archiver not found"; } | |
| 51 | ✗ | case LinkerErrorType::LINKER_ERROR: { return "Linker error occurred"; } | |
| 52 | ✗ | case LinkerErrorType::SANITIZER_NOT_SUPPORTED_BY_LINKER_INVOKER: { return "Sanitizer not supported by linker invoker"; } | |
| 53 | − | default: { panic(Error("Unknown error")); } // LCOV_EXCL_LINE | |
| 54 | } | ||
| 55 | ✗ | } | |
| 56 |