@@ -31,20 +31,22 @@ function getConfigFile () {
3131function checkConfigFile ( ) {
3232 const configFileName = getConfigFile ( ) ;
3333
34- // Check if file is present
35- if ( fs . existsSync ( configFileName ) === false ) {
36- throw new Error ( `File not found: ${ configFileName } \nNo config file present!` ) ;
37- }
38-
39- // Check permission
34+ // Check if file exists and is accessible
4035 try {
41- fs . accessSync ( configFileName , fs . constants . F_OK ) ;
36+ fs . accessSync ( configFileName , fs . constants . R_OK ) ;
4237 } catch ( error ) {
43- throw new Error ( `${ error } \nNo permission to access config file!` ) ;
38+ if ( error . code === "ENOENT" ) {
39+ Log . error ( `[check_config] File not found: ${ configFileName } ` ) ;
40+ } else if ( error . code === "EACCES" ) {
41+ Log . error ( `[check_config] No permission to read config file: ${ configFileName } ` ) ;
42+ } else {
43+ Log . error ( `[check_config] Cannot access config file: ${ configFileName } \n${ error . message } ` ) ;
44+ }
45+ process . exit ( 1 ) ;
4446 }
4547
4648 // Validate syntax of the configuration file.
47- Log . info ( `[checkconfig ] Checking config file ${ configFileName } ...` ) ;
49+ Log . info ( `[check_config ] Checking config file ${ configFileName } ...` ) ;
4850
4951 // I'm not sure if all ever is utf-8
5052 const configFile = fs . readFileSync ( configFileName , "utf-8" ) ;
@@ -67,15 +69,16 @@ function checkConfigFile () {
6769 ) ;
6870
6971 if ( errors . length === 0 ) {
70- Log . info ( styleText ( "green" , "[checkconfig ] Your configuration file doesn't contain syntax errors :)" ) ) ;
72+ Log . info ( styleText ( "green" , "[check_config ] Your configuration file doesn't contain syntax errors :)" ) ) ;
7173 validateModulePositions ( configFileName ) ;
7274 } else {
73- let errorMessage = "Your configuration file contains syntax errors :(" ;
75+ let errorMessage = "[check_config] Your configuration file contains syntax errors :(" ;
7476
7577 for ( const error of errors ) {
7678 errorMessage += `\nLine ${ error . line } column ${ error . column } : ${ error . message } ` ;
7779 }
78- throw new Error ( errorMessage ) ;
80+ Log . error ( errorMessage ) ;
81+ process . exit ( 1 ) ;
7982 }
8083}
8184
@@ -84,7 +87,7 @@ function checkConfigFile () {
8487 * @param {string } configFileName - The path and filename of the configuration file to validate.
8588 */
8689function validateModulePositions ( configFileName ) {
87- Log . info ( "[checkconfig ] Checking modules structure configuration ..." ) ;
90+ Log . info ( "[check_config ] Checking modules structure configuration ..." ) ;
8891
8992 const positionList = Utils . getModulePositions ( ) ;
9093
@@ -118,7 +121,7 @@ function validateModulePositions (configFileName) {
118121
119122 const valid = validate ( data ) ;
120123 if ( valid ) {
121- Log . info ( styleText ( "green" , "[checkconfig ] Your modules structure configuration doesn't contain errors :)" ) ) ;
124+ Log . info ( styleText ( "green" , "[check_config ] Your modules structure configuration doesn't contain errors :)" ) ) ;
122125 } else {
123126 const module = validate . errors [ 0 ] . instancePath . split ( "/" ) [ 2 ] ;
124127 const position = validate . errors [ 0 ] . instancePath . split ( "/" ) [ 3 ] ;
@@ -130,13 +133,15 @@ function validateModulePositions (configFileName) {
130133 } else {
131134 errorMessage += validate . errors [ 0 ] . message ;
132135 }
133- Log . error ( "[checkconfig]" , errorMessage ) ;
136+ Log . error ( "[check_config]" , errorMessage ) ;
137+ process . exit ( 1 ) ;
134138 }
135139}
136140
137141try {
138142 checkConfigFile ( ) ;
139143} catch ( error ) {
140- Log . error ( "[checkconfig]" , error ) ;
144+ const message = error && error . message ? error . message : error ;
145+ Log . error ( `[check_config] Unexpected error: ${ message } ` ) ;
141146 process . exit ( 1 ) ;
142147}
0 commit comments