Fix crash possibility if module: <name> is not defined and on mistake position: <position> (#3445)

Fix #3442
This commit is contained in:
Bugsounet - Cédric
2024-06-24 21:51:54 +02:00
committed by GitHub
parent 4c748a4d32
commit e95c144c3e
8 changed files with 170 additions and 21 deletions

View File

@@ -5,6 +5,10 @@ const { Linter } = require("eslint");
const linter = new Linter();
const Ajv = require("ajv");
const ajv = new Ajv();
const rootPath = path.resolve(`${__dirname}/../`);
const Log = require(`${rootPath}/js/logger.js`);
@@ -59,6 +63,68 @@ function checkConfigFile () {
for (const error of errors) {
Log.error(`Line ${error.line} column ${error.column}: ${error.message}`);
}
return;
}
Log.info("Checking modules structure configuration... ");
// Make Ajv schema confguration of modules config
// only scan "module" and "position"
const schema = {
type: "object",
properties: {
modules: {
type: "array",
items: {
type: "object",
properties: {
module: {
type: "string"
},
position: {
type: "string",
enum: [
"top_bar",
"top_left",
"top_center",
"top_right",
"upper_third",
"middle_center",
"lower_third",
"bottom_left",
"bottom_center",
"bottom_right",
"bottom_bar",
"fullscreen_above",
"fullscreen_below"
]
}
},
required: ["module"]
}
}
}
};
// scan all modules
const validate = ajv.compile(schema);
const data = require(configFileName);
const valid = validate(data);
if (!valid) {
let module = validate.errors[0].instancePath.split("/")[2];
let position = validate.errors[0].instancePath.split("/")[3];
Log.error(colors.red("This module configuration contains errors:"));
Log.error(data.modules[module]);
if (position) {
Log.error(colors.red(`${position}: ${validate.errors[0].message}`));
Log.error(validate.errors[0].params.allowedValues);
} else {
Log.error(colors.red(validate.errors[0].message));
}
} else {
Log.info(colors.green("Your modules structure configuration doesn't contain errors :)"));
}
}