config-loader,cli: better presentation of config schema validation errors
This commit is contained in:
@@ -104,10 +104,14 @@ export function compileConfigSchemas(
|
||||
|
||||
const valid = validate(config);
|
||||
if (!valid) {
|
||||
// TODO(Rugvip): better messages here, with more context such as which file the error occurred in
|
||||
const errors = ajv.errorsText(validate.errors);
|
||||
const errors = validate.errors ?? [];
|
||||
return {
|
||||
errors: [errors],
|
||||
errors: errors.map(({ dataPath, message, params }) => {
|
||||
const paramStr = Object.entries(params)
|
||||
.map(([name, value]) => `${name}=${value}`)
|
||||
.join(' ');
|
||||
return `Config ${message || ''} { ${paramStr} } at ${dataPath}`;
|
||||
}),
|
||||
visibilityByPath: new Map(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -61,9 +61,11 @@ export async function loadConfigSchema(
|
||||
): AppConfig[] {
|
||||
const result = validate(configs);
|
||||
if (result.errors) {
|
||||
throw new Error(
|
||||
const error = new Error(
|
||||
`Config validation failed, ${result.errors.join('; ')}`,
|
||||
);
|
||||
(error as any).messages = result.errors;
|
||||
throw error;
|
||||
}
|
||||
|
||||
let processedConfigs = configs;
|
||||
|
||||
Reference in New Issue
Block a user