import { ConfigService , ConfigValidateParameters } from '@kbn/config' ; import { CriticalError } from '../errors' ; const ignoredPaths = [ 'dev.' , 'elastic.apm.' ] ; const invalidConfigExitCode = 78 ; const legacyInvalidConfigExitCode = 64 ; export async function ensureValidConfiguration ( configService , params ? ) { try { await configService . validate ( params ) ; } catch ( e ) { throw new CriticalError ( e . message , 'InvalidConfig' , invalidConfigExitCode , e ) ; } const unusedPaths = await configService . getUnusedPaths ( ) ; const unusedConfigKeys = unusedPaths . filter ( ( unusedPath ) => { return ! ignoredPaths . some ( ( ignoredPath ) => unusedPath . startsWith ( ignoredPath ) ) ; } ) ; if ( unusedConfigKeys . length > 0 ) { const message = `Unknown configuration key(s): ${ unusedConfigKeys . map ( ( key ) => `"${ key }"` ) . join ( ', ' ) }. Check for spelling errors and ensure that expected plugins are installed.` ; throw new CriticalError ( message , 'InvalidConfig' , legacyInvalidConfigExitCode ) ; } }