import { validate as sValidate , Failure } from "superstruct" ; import { Config , configSchema } from "./types" ; function formatErrors ( failures ) { return [ 'Config file "kosko.toml" is invalid.' , ... failures . map ( ( f ) => `- "${ f . path . join ( "." ) }": ${ f . message }` ) ] . join ( "\n" ) ; } export class ValidationError extends Error { constructor ( public readonly errors ) { super ( formatErrors ( errors ) ) ; } } ValidationError . prototype . name = "ValidationError" ; param data export function validate ( data ) { const result = sValidate ( data , configSchema ) ; if ( result [ 0 ] ) { throw new ValidationError ( result [ 0 ] . failures ( ) ) ; } return result [ 1 ] ; }