2025-08-07 09:55:59 +02:00
"use strict" ;
2025-08-07 15:43:56 +02:00
var _ _createBinding = ( this && this . _ _createBinding ) || ( Object . create ? ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
var desc = Object . getOwnPropertyDescriptor ( m , k ) ;
if ( ! desc || ( "get" in desc ? ! m . _ _esModule : desc . writable || desc . configurable ) ) {
desc = { enumerable : true , get : function ( ) { return m [ k ] ; } } ;
}
Object . defineProperty ( o , k2 , desc ) ;
} ) : ( function ( o , m , k , k2 ) {
if ( k2 === undefined ) k2 = k ;
o [ k2 ] = m [ k ] ;
} ) ) ;
var _ _setModuleDefault = ( this && this . _ _setModuleDefault ) || ( Object . create ? ( function ( o , v ) {
Object . defineProperty ( o , "default" , { enumerable : true , value : v } ) ;
} ) : function ( o , v ) {
o [ "default" ] = v ;
} ) ;
var _ _importStar = ( this && this . _ _importStar ) || ( function ( ) {
var ownKeys = function ( o ) {
ownKeys = Object . getOwnPropertyNames || function ( o ) {
var ar = [ ] ;
for ( var k in o ) if ( Object . prototype . hasOwnProperty . call ( o , k ) ) ar [ ar . length ] = k ;
return ar ;
} ;
return ownKeys ( o ) ;
} ;
return function ( mod ) {
if ( mod && mod . _ _esModule ) return mod ;
var result = { } ;
if ( mod != null ) for ( var k = ownKeys ( mod ) , i = 0 ; i < k . length ; i ++ ) if ( k [ i ] !== "default" ) _ _createBinding ( result , mod , k [ i ] ) ;
_ _setModuleDefault ( result , mod ) ;
return result ;
} ;
} ) ( ) ;
2025-08-07 09:55:59 +02:00
var _ _importDefault = ( this && this . _ _importDefault ) || function ( mod ) {
return ( mod && mod . _ _esModule ) ? mod : { "default" : mod } ;
} ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
const ava _1 = _ _importDefault ( require ( "ava" ) ) ;
2025-08-07 15:43:56 +02:00
const sinon = _ _importStar ( require ( "sinon" ) ) ;
2025-08-07 09:55:59 +02:00
const actions _util _1 = require ( "./actions-util" ) ;
const cli _errors _1 = require ( "./cli-errors" ) ;
const testing _utils _1 = require ( "./testing-utils" ) ;
const util _1 = require ( "./util" ) ;
( 0 , testing _utils _1 . setupTests ) ( ava _1 . default ) ;
( 0 , ava _1 . default ) ( "CliError constructor with fatal errors" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "finalize" ] , 32 , "Running TRAP import for CodeQL database...\nA fatal error occurred: Evaluator heap must be at least 384.00 MiB\nA fatal error occurred: Dataset import failed with code 2" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . is ( cliError . exitCode , 32 ) ;
t . is ( cliError . stderr , "Running TRAP import for CodeQL database...\nA fatal error occurred: Evaluator heap must be at least 384.00 MiB\nA fatal error occurred: Dataset import failed with code 2" ) ;
t . true ( cliError . message . includes ( "A fatal error occurred: Dataset import failed with code 2." ) ) ;
t . true ( cliError . message . includes ( "Context: A fatal error occurred: Evaluator heap must be at least 384.00 MiB." ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "CliError constructor with single fatal error" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "A fatal error occurred: Out of memory" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . is ( cliError . exitCode , 1 ) ;
t . true ( cliError . message . includes ( "A fatal error occurred: Out of memory" ) ) ;
t . false ( cliError . message . includes ( "Context:" ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "CliError constructor with autobuild errors" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "[autobuild] [ERROR] Build failed\n[autobuild] [ERROR] Compilation error" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . is ( cliError . exitCode , 1 ) ;
t . true ( cliError . message . includes ( "We were unable to automatically build your code" ) ) ;
t . true ( cliError . message . includes ( "Build failed\nCompilation error" ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "CliError constructor with truncated autobuild errors" , ( t ) => {
const stderr = Array . from ( { length : 12 } , ( _ , i ) => ` [autobuild] [ERROR] Error ${ i + 1 } ` ) . join ( "\n" ) ;
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , stderr ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . true ( cliError . message . includes ( "(truncated)" ) ) ;
// Should only include first 10 errors plus truncation message
const errorLines = cliError . message
. split ( "Encountered the following error: " ) [ 1 ]
. split ( "\n" ) ;
t . is ( errorLines . length , 11 ) ; // 10 errors + "(truncated)"
} ) ;
( 0 , ava _1 . default ) ( "CliError constructor with generic error" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "Some generic error message\nLast line of error" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . is ( cliError . exitCode , 1 ) ;
t . true ( cliError . message . includes ( 'Encountered a fatal error while running "codeql version"' ) ) ;
t . true ( cliError . message . includes ( "Exit code was 1 and last log line was: Last line of error." ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "CliError constructor with empty stderr" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
t . true ( cliError . message . includes ( "last log line was: n/a" ) ) ;
} ) ;
2025-08-07 15:43:56 +02:00
for ( const [ platform , arch ] of [
[ "weird_plat" , "x64" ] ,
[ "linux" , "arm64" ] ,
[ "win32" , "arm64" ] ,
] ) {
( 0 , ava _1 . default ) ( ` wrapCliConfigurationError - ${ platform } / ${ arch } unsupported ` , ( t ) => {
sinon . stub ( process , "platform" ) . value ( platform ) ;
sinon . stub ( process , "arch" ) . value ( arch ) ;
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "Some error" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
t . true ( wrappedError . message . includes ( "CodeQL CLI does not support the platform/architecture combination" ) ) ;
2025-08-07 15:43:56 +02:00
t . true ( wrappedError . message . includes ( ` ${ platform } / ${ arch } ` ) ) ;
} ) ;
}
2025-08-07 09:55:59 +02:00
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - supported platform" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "Some error" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
// Should return the original error since platform is supported
t . is ( wrappedError , cliError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - autobuild error" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "We were unable to automatically build your code" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
t . true ( wrappedError . message . includes ( "We were unable to automatically build your code" ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - init called twice" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "Refusing to create databases /some/path but could not process any of it" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
t . true ( wrappedError . message . includes ( 'Is the "init" action called twice in the same job?' ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - no source code seen by exit code" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "finalize" ] , 32 , "Some other error message" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - no source code seen by message" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "finalize" ] , 1 , "CodeQL detected code written in JavaScript but could not process any of it" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - out of memory error with additional message" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "analyze" ] , 1 , "CodeQL is out of memory." ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
t . true ( wrappedError . message . includes ( "For more information, see https://gh.io/troubleshooting-code-scanning/out-of-disk-or-memory" ) ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - gradle build failed" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "[autobuild] FAILURE: Build failed with an exception." ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - maven build failed" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "[autobuild] [ERROR] Failed to execute goal" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - swift build failed" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "[autobuilder/build] [build-command-failed] `autobuild` failed to run the build command" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - pack cannot be found" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "pack" , "install" ] , 1 , "Query pack my-pack cannot be found. Check the spelling of the pack." ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - pack missing auth" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "pack" , "download" ] , 1 , "GitHub Container registry returned 403 Forbidden" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - invalid config file" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "database" , "create" ] , 1 , "Config file .codeql/config.yml is not valid" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - incompatible CLI version" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "is not compatible with this CodeQL CLI" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
t . true ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
( 0 , ava _1 . default ) ( "wrapCliConfigurationError - unknown error remains unchanged" , ( t ) => {
2025-08-07 15:43:56 +02:00
const commandError = new actions _util _1 . CommandInvocationError ( "codeql" , [ "version" ] , 1 , "Some unknown error that doesn't match any patterns" ) ;
2025-08-07 09:55:59 +02:00
const cliError = new cli _errors _1 . CliError ( commandError ) ;
const wrappedError = ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( cliError ) ;
// Should return the original CliError since it doesn't match any known patterns
t . is ( wrappedError , cliError ) ;
t . true ( wrappedError instanceof cli _errors _1 . CliError ) ;
t . false ( wrappedError instanceof util _1 . ConfigurationError ) ;
} ) ;
// Test all error categories to ensure they're properly configured
( 0 , ava _1 . default ) ( "all CLI config error categories have valid configurations" , ( t ) => {
const allCategories = Object . values ( cli _errors _1 . CliConfigErrorCategory ) ;
for ( const category of allCategories ) {
// Each category should be a string
t . is ( typeof category , "string" ) ;
// Create a test error that matches this category
let testError ;
switch ( category ) {
case cli _errors _1 . CliConfigErrorCategory . NoSourceCodeSeen :
// This category matches by exit code
2025-08-07 15:43:56 +02:00
testError = new cli _errors _1 . CliError ( new actions _util _1 . CommandInvocationError ( "codeql" , [ ] , 32 , "some error" ) ) ;
2025-08-07 09:55:59 +02:00
break ;
default :
// For other categories, we'll test with a generic message that should not match
2025-08-07 15:43:56 +02:00
testError = new cli _errors _1 . CliError ( new actions _util _1 . CommandInvocationError ( "codeql" , [ ] , 1 , "generic error" ) ) ;
2025-08-07 09:55:59 +02:00
break ;
}
// The test should not throw an error when processing
t . notThrows ( ( ) => ( 0 , cli _errors _1 . wrapCliConfigurationError ) ( testError ) ) ;
}
} ) ;
//# sourceMappingURL=cli-errors.test.js.map