-
Notifications
You must be signed in to change notification settings - Fork 377
Make all errors on an unsupported platform ConfigurationError
s
#3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
ConfigurationError
s
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,7 +294,7 @@ export const cliErrorsConfig: Record< | |
* the error messages in the config record, or the exit codes match, return the error category; | ||
* if not, return undefined. | ||
*/ | ||
export function getCliConfigCategoryIfExists( | ||
function getCliConfigCategoryIfExists( | ||
cliError: CliError, | ||
): CliConfigErrorCategory | undefined { | ||
for (const [category, configuration] of Object.entries(cliErrorsConfig)) { | ||
|
@@ -317,11 +317,45 @@ export function getCliConfigCategoryIfExists( | |
} | ||
|
||
/** | ||
* Changes an error received from the CLI to a ConfigurationError with optionally an extra | ||
* error message appended, if it exists in a known set of configuration errors. Otherwise, | ||
* Check if we are running on an unsupported platform/architecture combination. | ||
* If so, return a ConfigurationError with a message that explains that, mentioning | ||
* the underlying `cliError`. Otherwise, reutrn `undefined`. | ||
*/ | ||
function getUnsupportedPlatformError( | ||
cliError: CliError, | ||
): ConfigurationError | undefined { | ||
if ( | ||
![ | ||
["linux", "x64"], | ||
["win32", "x64"], | ||
["darwin", "x64"], | ||
["darwin", "arm64"], | ||
].some( | ||
([platform, arch]) => | ||
platform === process.platform && arch === process.arch, | ||
) | ||
) { | ||
return new ConfigurationError( | ||
"The CodeQL CLI does not support the platform/architecture combination of " + | ||
`${process.platform}/${process.arch} ` + | ||
"(see https://codeql.github.com/docs/codeql-overview/system-requirements). " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Should we add this to the |
||
`The underlying error was: ${cliError.message}`, | ||
); | ||
} | ||
return undefined; | ||
} | ||
|
||
/** | ||
* Changes an error received from the CLI to a ConfigurationError with the message | ||
* optionally being transformed, if it is a known configuration error. Otherwise, | ||
* simply returns the original error. | ||
*/ | ||
export function wrapCliConfigurationError(cliError: CliError): Error { | ||
const unsupportedPlatformError = getUnsupportedPlatformError(cliError); | ||
if (unsupportedPlatformError !== undefined) { | ||
return unsupportedPlatformError; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems a bit like an improvised try/catch block. Why not just return a bool from a function that checks if the platform is supported and then throw the error here? |
||
|
||
const cliConfigErrorCategory = getCliConfigCategoryIfExists(cliError); | ||
if (cliConfigErrorCategory === undefined) { | ||
return cliError; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: It might be nicer if this array was a top-level constant, rather than inlined here.