Refactoring: Simplify retrieving error message

This commit is contained in:
Henry Mercer 2024-09-16 22:38:35 +02:00
parent bbd7c801a0
commit dd7307d603
54 changed files with 106 additions and 89 deletions

8
lib/util.js generated
View file

@ -784,8 +784,14 @@ function fixInvalidNotificationsInFile(inputPath, outputPath, logger) {
function wrapError(error) {
return error instanceof Error ? error : new Error(String(error));
}
/**
* Returns an appropriate message for the error.
*
* If the error is an `Error` instance, this returns the error message without
* an `Error: ` prefix.
*/
function getErrorMessage(error) {
return error instanceof Error ? error.toString() : String(error);
return error instanceof Error ? error.message : String(error);
}
function prettyPrintPack(pack) {
return `${pack.name}${pack.version ? `@${pack.version}` : ""}${pack.path ? `:${pack.path}` : ""}`;