Improve error categorizations

This commit is contained in:
Henry Mercer
2023-12-01 17:54:38 +00:00
parent db40ac46b9
commit 1d367b0bec
24 changed files with 47 additions and 38 deletions

View File

@@ -120,7 +120,7 @@ export function getExtraOptionsEnvParam(): object {
return JSON.parse(raw);
} catch (unwrappedError) {
const error = wrapError(unwrappedError);
throw new Error(
throw new UserError(
`${varName} environment variable is set, but does not contain valid JSON: ${error.message}`,
);
}
@@ -204,7 +204,7 @@ export function getMemoryFlagValueForPlatform(
if (userInput) {
memoryToUseMegaBytes = Number(userInput);
if (Number.isNaN(memoryToUseMegaBytes) || memoryToUseMegaBytes <= 0) {
throw new Error(`Invalid RAM setting "${userInput}", specified.`);
throw new UserError(`Invalid RAM setting "${userInput}", specified.`);
}
} else {
const totalMemoryMegaBytes = totalMemoryBytes / (1024 * 1024);
@@ -358,7 +358,7 @@ export function getThreadsFlagValue(
if (userInput) {
numThreads = Number(userInput);
if (Number.isNaN(numThreads)) {
throw new Error(`Invalid threads setting "${userInput}", specified.`);
throw new UserError(`Invalid threads setting "${userInput}", specified.`);
}
if (numThreads > maxThreads) {
logger.info(
@@ -412,14 +412,14 @@ export function parseGitHubUrl(inputUrl: string): string {
inputUrl = `https://${inputUrl}`;
}
if (!inputUrl.startsWith("http://") && !inputUrl.startsWith("https://")) {
throw new Error(`"${originalUrl}" is not a http or https URL`);
throw new UserError(`"${originalUrl}" is not a http or https URL`);
}
let url: URL;
try {
url = new URL(inputUrl);
} catch (e) {
throw new Error(`"${originalUrl}" is not a valid URL`);
throw new UserError(`"${originalUrl}" is not a valid URL`);
}
// If we detect this is trying to be to github.com