mirror of
https://github.com/github/codeql-action.git
synced 2026-01-05 14:10:11 +08:00
Improve error categorizations
This commit is contained in:
@@ -187,7 +187,7 @@ export async function getRef(): Promise<string> {
|
||||
const hasShaInput = !!shaInput;
|
||||
// If one of 'ref' or 'sha' are provided, both are required
|
||||
if ((hasRefInput || hasShaInput) && !(hasRefInput && hasShaInput)) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
"Both 'ref' and 'sha' are required if one of them is provided.",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import { DatabaseCreationTimings, EventReport } from "./status-report";
|
||||
import { endTracingForCluster } from "./tracer-config";
|
||||
import { validateSarifFileSchema } from "./upload-lib";
|
||||
import * as util from "./util";
|
||||
import { UserError } from "./util";
|
||||
|
||||
export class CodeQLAnalysisError extends Error {
|
||||
queriesStatusReport: QueriesStatusReport;
|
||||
@@ -297,7 +298,7 @@ export async function runQueries(
|
||||
!hasCustomQueries &&
|
||||
!hasPackWithCustomQueries
|
||||
) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`Unable to analyze ${language} as no queries were selected for this language`,
|
||||
);
|
||||
}
|
||||
@@ -614,7 +615,7 @@ export function validateQueryFilters(queryFilters?: configUtils.QueryFilter[]) {
|
||||
}
|
||||
|
||||
if (!Array.isArray(queryFilters)) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`Query filters must be an array of "include" or "exclude" entries. Found ${typeof queryFilters}`,
|
||||
);
|
||||
}
|
||||
@@ -637,7 +638,7 @@ export function validateQueryFilters(queryFilters?: configUtils.QueryFilter[]) {
|
||||
}
|
||||
|
||||
if (errors.length) {
|
||||
throw new Error(`Invalid query filter.\n${errors.join("\n")}`);
|
||||
throw new UserError(`Invalid query filter.\n${errors.join("\n")}`);
|
||||
}
|
||||
|
||||
return queryFilters;
|
||||
|
||||
@@ -418,7 +418,7 @@ export async function setupCodeQL(
|
||||
if (process.platform === "win32") {
|
||||
codeqlCmd += ".exe";
|
||||
} else if (process.platform !== "linux" && process.platform !== "darwin") {
|
||||
throw new Error(`Unsupported platform: ${process.platform}`);
|
||||
throw new util.UserError(`Unsupported platform: ${process.platform}`);
|
||||
}
|
||||
|
||||
cachedCodeQL = await getCodeQLForCmd(codeqlCmd, checkVersion);
|
||||
@@ -1150,7 +1150,7 @@ export async function getCodeQLForCmd(
|
||||
checkVersion &&
|
||||
!(await util.codeQlVersionAbove(codeql, CODEQL_MINIMUM_VERSION))
|
||||
) {
|
||||
throw new Error(
|
||||
throw new util.UserError(
|
||||
`Expected a CodeQL CLI with version at least ${CODEQL_MINIMUM_VERSION} but got version ${
|
||||
(await codeql.getVersion()).version
|
||||
}`,
|
||||
|
||||
@@ -6,6 +6,7 @@ import * as safeWhich from "@chrisgavin/safe-which";
|
||||
|
||||
import { GitHubApiExternalRepoDetails } from "./api-client";
|
||||
import { Logger } from "./logging";
|
||||
import { UserError } from "./util";
|
||||
|
||||
/**
|
||||
* Check out repository at the given ref, and return the directory of the checkout.
|
||||
@@ -23,7 +24,7 @@ export async function checkoutExternalRepository(
|
||||
|
||||
if (!checkoutLocation.startsWith(tempDir)) {
|
||||
// this still permits locations that mess with sibling repositories in `tempDir`, but that is acceptable
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`'${repository}@${ref}' is not a valid repository and reference.`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { UserError } from "./util";
|
||||
|
||||
// A repository name with owner, parsed into its two parts
|
||||
export interface RepositoryNwo {
|
||||
owner: string;
|
||||
@@ -7,7 +9,7 @@ export interface RepositoryNwo {
|
||||
export function parseRepositoryNwo(input: string): RepositoryNwo {
|
||||
const parts = input.split("/");
|
||||
if (parts.length !== 2) {
|
||||
throw new Error(`"${input}" is not a valid repository name`);
|
||||
throw new UserError(`"${input}" is not a valid repository name`);
|
||||
}
|
||||
return {
|
||||
owner: parts[0],
|
||||
|
||||
@@ -27,7 +27,9 @@ export async function runResolveBuildEnvironment(
|
||||
) {
|
||||
const parsedLanguage = parseLanguage(languageInput)?.toString();
|
||||
if (parsedLanguage === undefined) {
|
||||
throw new Error(`Did not recognize the language '${languageInput}'.`);
|
||||
throw new util.UserError(
|
||||
`Did not recognize the language '${languageInput}'.`,
|
||||
);
|
||||
}
|
||||
language = parsedLanguage;
|
||||
}
|
||||
|
||||
@@ -647,7 +647,7 @@ export async function downloadCodeQL(
|
||||
export function getCodeQLURLVersion(url: string): string {
|
||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||
if (match === null || match.length < 2) {
|
||||
throw new Error(
|
||||
throw new util.UserError(
|
||||
`Malformed tools url: ${url}. Version could not be inferred`,
|
||||
);
|
||||
}
|
||||
|
||||
10
src/util.ts
10
src/util.ts
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user