config-loader,cli: better presentation of config schema validation errors

This commit is contained in:
Patrik Oldsberg
2020-11-15 13:07:13 +01:00
parent eb9e293fce
commit d02d79e392
3 changed files with 29 additions and 14 deletions
+19 -10
View File
@@ -40,15 +40,24 @@ export async function loadCliConfig(configArgs: string[]) {
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
);
const frontendAppConfigs = schema.process(appConfigs, {
visiblity: ['frontend'],
});
const frontendConfig = ConfigReader.fromConfigs(frontendAppConfigs);
try {
const frontendAppConfigs = schema.process(appConfigs, {
visiblity: ['frontend'],
});
const frontendConfig = ConfigReader.fromConfigs(frontendAppConfigs);
return {
schema,
appConfigs,
frontendConfig,
frontendAppConfigs,
};
return {
schema,
appConfigs,
frontendConfig,
frontendAppConfigs,
};
} catch (error) {
const maybeSchemaError = error as Error & { messages?: string[] };
if (maybeSchemaError.messages) {
const messages = maybeSchemaError.messages.join('\n ');
throw new Error(`Configuration does not match schema\n\n ${messages}`);
}
throw error;
}
}