@@ -3,7 +3,7 @@ import { InitBindOptions, InitElementConfig, InitElementType, InitPlatform } fro
33import * as iam from '../../aws-iam' ;
44import * as s3 from '../../aws-s3' ;
55import * as s3_assets from '../../aws-s3-assets' ;
6- import { Duration } from '../../core' ;
6+ import { Duration , UnscopedValidationError , ValidationError } from '../../core' ;
77import { md5hash } from '../../core/lib/helpers-internal' ;
88
99/**
@@ -220,7 +220,7 @@ export class InitCommand extends InitElement {
220220 */
221221 public static argvCommand ( argv : string [ ] , options : InitCommandOptions = { } ) : InitCommand {
222222 if ( argv . length === 0 ) {
223- throw new Error ( 'Cannot define argvCommand with an empty arguments' ) ;
223+ throw new UnscopedValidationError ( 'Cannot define argvCommand with an empty arguments' ) ;
224224 }
225225 return new InitCommand ( argv , options ) ;
226226 }
@@ -236,7 +236,7 @@ export class InitCommand extends InitElement {
236236 const commandKey = this . options . key || `${ options . index } ` . padStart ( 3 , '0' ) ; // 001, 005, etc.
237237
238238 if ( options . platform !== InitPlatform . WINDOWS && this . options . waitAfterCompletion !== undefined ) {
239- throw new Error ( `Command '${ this . command } ': 'waitAfterCompletion' is only valid for Windows systems.` ) ;
239+ throw new ValidationError ( `Command '${ this . command } ': 'waitAfterCompletion' is only valid for Windows systems.` , options . scope ) ;
240240 }
241241
242242 for ( const handle of this . options . serviceRestartHandles ?? [ ] ) {
@@ -325,7 +325,7 @@ export abstract class InitFile extends InitElement {
325325 */
326326 public static fromString ( fileName : string , content : string , options : InitFileOptions = { } ) : InitFile {
327327 if ( ! content ) {
328- throw new Error ( `InitFile ${ fileName } : cannot create empty file. Please supply at least one character of content.` ) ;
328+ throw new UnscopedValidationError ( `InitFile ${ fileName } : cannot create empty file. Please supply at least one character of content.` ) ;
329329 }
330330 return new class extends InitFile {
331331 protected _doBind ( bindOptions : InitBindOptions ) {
@@ -345,7 +345,7 @@ export abstract class InitFile extends InitElement {
345345 public static symlink ( fileName : string , target : string , options : InitFileOptions = { } ) : InitFile {
346346 const { mode, ...otherOptions } = options ;
347347 if ( mode && mode . slice ( 0 , 3 ) !== '120' ) {
348- throw new Error ( 'File mode for symlinks must begin with 120XXX' ) ;
348+ throw new UnscopedValidationError ( 'File mode for symlinks must begin with 120XXX' ) ;
349349 }
350350 return InitFile . fromString ( fileName , target , { mode : ( mode || '120644' ) , ...otherOptions } ) ;
351351 }
@@ -489,7 +489,7 @@ export abstract class InitFile extends InitElement {
489489 protected _standardConfig ( fileOptions : InitFileOptions , platform : InitPlatform , contentVars : Record < string , any > ) : Record < string , any > {
490490 if ( platform === InitPlatform . WINDOWS ) {
491491 if ( fileOptions . group || fileOptions . owner || fileOptions . mode ) {
492- throw new Error ( 'Owner, group, and mode options not supported for Windows.' ) ;
492+ throw new UnscopedValidationError ( 'Owner, group, and mode options not supported for Windows.' ) ;
493493 }
494494 return {
495495 [ this . fileName ] : { ...contentVars } ,
@@ -529,7 +529,7 @@ export class InitGroup extends InitElement {
529529 /** @internal */
530530 public _bind ( options : InitBindOptions ) : InitElementConfig {
531531 if ( options . platform === InitPlatform . WINDOWS ) {
532- throw new Error ( 'Init groups are not supported on Windows' ) ;
532+ throw new UnscopedValidationError ( 'Init groups are not supported on Windows' ) ;
533533 }
534534
535535 return {
@@ -593,7 +593,7 @@ export class InitUser extends InitElement {
593593 /** @internal */
594594 public _bind ( options : InitBindOptions ) : InitElementConfig {
595595 if ( options . platform === InitPlatform . WINDOWS ) {
596- throw new Error ( 'Init users are not supported on Windows' ) ;
596+ throw new UnscopedValidationError ( 'Init users are not supported on Windows' ) ;
597597 }
598598
599599 return {
@@ -712,14 +712,14 @@ export class InitPackage extends InitElement {
712712 public _bind ( options : InitBindOptions ) : InitElementConfig {
713713 if ( ( this . type === 'msi' ) !== ( options . platform === InitPlatform . WINDOWS ) ) {
714714 if ( this . type === 'msi' ) {
715- throw new Error ( 'MSI installers are only supported on Windows systems.' ) ;
715+ throw new UnscopedValidationError ( 'MSI installers are only supported on Windows systems.' ) ;
716716 } else {
717- throw new Error ( 'Windows only supports the MSI package type' ) ;
717+ throw new UnscopedValidationError ( 'Windows only supports the MSI package type' ) ;
718718 }
719719 }
720720
721721 if ( ! this . packageName && ! [ 'rpm' , 'msi' ] . includes ( this . type ) ) {
722- throw new Error ( 'Package name must be specified for all package types besides RPM and MSI.' ) ;
722+ throw new UnscopedValidationError ( 'Package name must be specified for all package types besides RPM and MSI.' ) ;
723723 }
724724
725725 const packageName = this . packageName || `${ options . index } ` . padStart ( 3 , '0' ) ;
@@ -826,11 +826,11 @@ export class InitService extends InitElement {
826826 */
827827 public static systemdConfigFile ( serviceName : string , options : SystemdConfigFileOptions ) : InitFile {
828828 if ( ! options . command . startsWith ( '/' ) ) {
829- throw new Error ( `SystemD executables must use an absolute path, got '${ options . command } '` ) ;
829+ throw new UnscopedValidationError ( `SystemD executables must use an absolute path, got '${ options . command } '` ) ;
830830 }
831831
832832 if ( options . environmentFiles ?. some ( file => ! file . startsWith ( '/' ) ) ) {
833- throw new Error ( 'SystemD environment files must use absolute paths' ) ;
833+ throw new UnscopedValidationError ( 'SystemD environment files must use absolute paths' ) ;
834834 }
835835
836836 const lines = [
0 commit comments