Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ planned for 2026-01-01
### Changed

- [core] refactor: replace `module-alias` dependency with internal alias resolver (#3893)
- [check_config] refactor: improve error handling (#3927)

### Fixed

Expand Down
40 changes: 27 additions & 13 deletions js/check_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ function getConfigFile () {
function checkConfigFile () {
const configFileName = getConfigFile();

// Check if file is present
if (fs.existsSync(configFileName) === false) {
throw new Error(`File not found: ${configFileName}\nNo config file present!`);
}

// Check permission
// Check if file exists and is accessible
try {
fs.accessSync(configFileName, fs.constants.F_OK);
fs.accessSync(configFileName, fs.constants.R_OK);
} catch (error) {
throw new Error(`${error}\nNo permission to access config file!`);
if (error.code === "ENOENT") {
Log.error(`File not found: ${configFileName}`);
} else if (error.code === "EACCES") {
Log.error(`No permission to read config file: ${configFileName}`);
} else {
Log.error(`Cannot access config file: ${configFileName}\n${error.message}`);
}
process.exit(1);
}

// Validate syntax of the configuration file.
Expand Down Expand Up @@ -75,7 +77,8 @@ function checkConfigFile () {
for (const error of errors) {
errorMessage += `\nLine ${error.line} column ${error.column}: ${error.message}`;
}
throw new Error(errorMessage);
Log.error(errorMessage);
process.exit(1);
}
}

Expand All @@ -102,8 +105,7 @@ function validateModulePositions (configFileName) {
type: "string"
},
position: {
type: "string",
enum: positionList
type: "string"
}
},
required: ["module"]
Expand All @@ -119,6 +121,16 @@ function validateModulePositions (configFileName) {
const valid = validate(data);
if (valid) {
Log.info(styleText("green", "Your modules structure configuration doesn't contain errors :)"));

// Check for unknown positions (warning only, not an error)
if (data.modules) {
for (const [index, module] of data.modules.entries()) {
if (module.position && !positionList.includes(module.position)) {
Log.warn(`Module ${index} ("${module.module}") uses unknown position: "${module.position}"`);
Log.warn(`Known positions are: ${positionList.join(", ")}`);
}
}
}
} else {
const module = validate.errors[0].instancePath.split("/")[2];
const position = validate.errors[0].instancePath.split("/")[3];
Expand All @@ -130,13 +142,15 @@ function validateModulePositions (configFileName) {
} else {
errorMessage += validate.errors[0].message;
}
Log.error("[checkconfig]", errorMessage);
Log.error(errorMessage);
process.exit(1);
}
}

try {
checkConfigFile();
} catch (error) {
Log.error("[checkconfig]", error);
const message = error && error.message ? error.message : error;
Log.error(`Unexpected error: ${message}`);
process.exit(1);
}