You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A way to do partial validation is needed for the cases where value from incomplete config is used to finish setting it up.
With sample code below node index.js --config config.js will fail (hopefully) on loadFile()
const convict = require('convict');
const path = require('path');
convict.addFormat({
name: 'configfile',
validate: (val) => {
// Some sample checks
if (typeof val !== 'string' || ! val.endsWith('.json')) {
throw new TypeError('Path must be a string pointing to json file');
}
},
coerce: (val) => {
return path.resolve(val);
},
});
const conf = convict({
config: {
doc: 'Configuration file to use',
format: 'configfile',
default: path.resolve(__dirname, 'config.json'),
arg: 'config',
},
});
// fs, json5 or some other error is thrown here
conf.loadFile(conf.get('config'));
And with partial validation we can be sure values are good:
// validate 'config' only, validation error will be thrown here and loadFile will never be reached
conf.validate({}, ['config']);
conf.loadFile(conf.get('config'));
This case is fairly safe, but it gets more important if, for example, that value is used to fetch config from external storage
The text was updated successfully, but these errors were encountered:
A way to do partial validation is needed for the cases where value from incomplete config is used to finish setting it up.
With sample code below
node index.js --config config.js
will fail (hopefully) onloadFile()
And with partial validation we can be sure values are good:
This case is fairly safe, but it gets more important if, for example, that value is used to fetch config from external storage
The text was updated successfully, but these errors were encountered: