@@ -3,7 +3,7 @@ import { InitBindOptions, InitElementConfig, InitElementType, InitPlatform } fro
3
3
import * as iam from '../../aws-iam' ;
4
4
import * as s3 from '../../aws-s3' ;
5
5
import * as s3_assets from '../../aws-s3-assets' ;
6
- import { Duration } from '../../core' ;
6
+ import { Duration , UnscopedValidationError , ValidationError } from '../../core' ;
7
7
import { md5hash } from '../../core/lib/helpers-internal' ;
8
8
9
9
/**
@@ -220,7 +220,7 @@ export class InitCommand extends InitElement {
220
220
*/
221
221
public static argvCommand ( argv : string [ ] , options : InitCommandOptions = { } ) : InitCommand {
222
222
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' ) ;
224
224
}
225
225
return new InitCommand ( argv , options ) ;
226
226
}
@@ -236,7 +236,7 @@ export class InitCommand extends InitElement {
236
236
const commandKey = this . options . key || `${ options . index } ` . padStart ( 3 , '0' ) ; // 001, 005, etc.
237
237
238
238
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 ) ;
240
240
}
241
241
242
242
for ( const handle of this . options . serviceRestartHandles ?? [ ] ) {
@@ -325,7 +325,7 @@ export abstract class InitFile extends InitElement {
325
325
*/
326
326
public static fromString ( fileName : string , content : string , options : InitFileOptions = { } ) : InitFile {
327
327
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.` ) ;
329
329
}
330
330
return new class extends InitFile {
331
331
protected _doBind ( bindOptions : InitBindOptions ) {
@@ -345,7 +345,7 @@ export abstract class InitFile extends InitElement {
345
345
public static symlink ( fileName : string , target : string , options : InitFileOptions = { } ) : InitFile {
346
346
const { mode, ...otherOptions } = options ;
347
347
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' ) ;
349
349
}
350
350
return InitFile . fromString ( fileName , target , { mode : ( mode || '120644' ) , ...otherOptions } ) ;
351
351
}
@@ -489,7 +489,7 @@ export abstract class InitFile extends InitElement {
489
489
protected _standardConfig ( fileOptions : InitFileOptions , platform : InitPlatform , contentVars : Record < string , any > ) : Record < string , any > {
490
490
if ( platform === InitPlatform . WINDOWS ) {
491
491
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.' ) ;
493
493
}
494
494
return {
495
495
[ this . fileName ] : { ...contentVars } ,
@@ -529,7 +529,7 @@ export class InitGroup extends InitElement {
529
529
/** @internal */
530
530
public _bind ( options : InitBindOptions ) : InitElementConfig {
531
531
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' ) ;
533
533
}
534
534
535
535
return {
@@ -593,7 +593,7 @@ export class InitUser extends InitElement {
593
593
/** @internal */
594
594
public _bind ( options : InitBindOptions ) : InitElementConfig {
595
595
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' ) ;
597
597
}
598
598
599
599
return {
@@ -712,14 +712,14 @@ export class InitPackage extends InitElement {
712
712
public _bind ( options : InitBindOptions ) : InitElementConfig {
713
713
if ( ( this . type === 'msi' ) !== ( options . platform === InitPlatform . WINDOWS ) ) {
714
714
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.' ) ;
716
716
} else {
717
- throw new Error ( 'Windows only supports the MSI package type' ) ;
717
+ throw new UnscopedValidationError ( 'Windows only supports the MSI package type' ) ;
718
718
}
719
719
}
720
720
721
721
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.' ) ;
723
723
}
724
724
725
725
const packageName = this . packageName || `${ options . index } ` . padStart ( 3 , '0' ) ;
@@ -826,11 +826,11 @@ export class InitService extends InitElement {
826
826
*/
827
827
public static systemdConfigFile ( serviceName : string , options : SystemdConfigFileOptions ) : InitFile {
828
828
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 } '` ) ;
830
830
}
831
831
832
832
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' ) ;
834
834
}
835
835
836
836
const lines = [
0 commit comments