@@ -14,6 +14,13 @@ const { getConfigFilePath } = require("#server_functions");
1414
1515const linter = new Linter ( { configType : "flat" } ) ;
1616
17+ class ConfigError extends Error {
18+ constructor ( message ) {
19+ super ( message ) ;
20+ this . name = "ConfigError" ;
21+ }
22+ }
23+
1724const requireFromString = ( src ) => {
1825 const m = new module . constructor ( ) ;
1926 m . _compile ( src , "" ) ;
@@ -172,7 +179,7 @@ const loadConfig = () => {
172179 } else {
173180 Log . error ( `Cannot access config file: ${ configFilename } \n${ error . message } ` ) ;
174181 }
175- throw new Error ( "process.exit:1" , { cause : error } ) ;
182+ throw new ConfigError ( "" ) ;
176183 }
177184} ;
178185
@@ -219,7 +226,7 @@ const checkConfigFile = (configObject) => {
219226 errorMessage += `\nLine ${ error . line } column ${ error . column } : ${ error . message } ` ;
220227 }
221228 Log . error ( errorMessage ) ;
222- throw new Error ( "process.exit:1 ") ;
229+ throw new ConfigError ( " ") ;
223230 }
224231} ;
225232
@@ -241,27 +248,27 @@ const validateModulePositions = (data) => {
241248 // `modules` always exists (defaults.js provides a default array), but guard against it being overridden with a non-array value
242249 if ( data . modules !== undefined && ! Array . isArray ( data . modules ) ) {
243250 Log . error ( "This module configuration contains errors:\nmodules must be an array" ) ;
244- throw new Error ( "process.exit:1 ") ;
251+ throw new ConfigError ( " ") ;
245252 }
246253
247254 // Validate each module entry
248255 for ( const [ index , mod ] of ( data . modules ?? [ ] ) . entries ( ) ) {
249256 // Each module entry must be an object so we can safely inspect its fields
250257 if ( mod === null || typeof mod !== "object" || Array . isArray ( mod ) ) {
251258 Log . error ( `This module configuration contains errors:\n${ JSON . stringify ( mod , null , 2 ) } \nmodule entry must be an object` ) ;
252- throw new Error ( "process.exit:1 ") ;
259+ throw new ConfigError ( " ") ;
253260 }
254261
255262 // `module` (the module name) is required and must be a string
256263 if ( typeof mod . module !== "string" ) {
257264 Log . error ( `This module configuration contains errors:\n${ JSON . stringify ( mod , null , 2 ) } \nmodule: must be a string` ) ;
258- throw new Error ( "process.exit:1 ") ;
265+ throw new ConfigError ( " ") ;
259266 }
260267
261268 // `position` is optional, but must be a string when provided
262269 if ( mod . position !== undefined && typeof mod . position !== "string" ) {
263270 Log . error ( `This module configuration contains errors:\n${ JSON . stringify ( mod , null , 2 ) } \nposition: must be a string` ) ;
264- throw new Error ( "process.exit:1 ") ;
271+ throw new ConfigError ( " ") ;
265272 }
266273
267274 // `position` is optional, but when set it must match a known region
@@ -274,4 +281,4 @@ const validateModulePositions = (data) => {
274281 Log . info ( styleText ( "green" , "Your modules structure configuration doesn't contain errors :)" ) ) ;
275282} ;
276283
277- module . exports = { loadConfig, getModulePositions, moduleHasValidPosition, getAvailableModulePositions, checkConfigFile } ;
284+ module . exports = { loadConfig, getModulePositions, moduleHasValidPosition, getAvailableModulePositions, checkConfigFile, ConfigError } ;
0 commit comments