-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Providing a default of undefined
prevents format from being checked
#278
Comments
If you hit this in your own usage, one workaround is to set a default of |
This is actually really useful for trying to implement optional config properties so... thanks! |
This was referenced Dec 7, 2019
validate don't check property with 5535379#diff-7763d1369911b91b757ba7ff51d734a2R65 Solutionvar convict = require("convict");
var config = convict({
something: {
format: function (val, schema) {
console.log(arguments);
if (schema.env && val === '') {
throw new Error(`env[${schema.env}] is not set !`)
}
if (typeof val === 'undefined' || val === null || val === '') {
throw new Error('must be a non-empty string');
}
},
default: '',
env: "SOMETHING",
},
});
config.validate({ allowed: 'strict' });
// If the `SOMETHING` env var isn't set, this will return `undefined` rather than erroring
// The format() function is never called
console.log(config.get('something')); |
This was referenced Jan 6, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The docs are clear that defaults must be supplied and, although the specifics could be improved (#254), not supplying a
default
value usually errors out.However, if
undefined
is given for a default value and the environment variable is alsoundefined
, the format function is never called. This results in bugs like this...Tested on
4.4.1
, see RunKitThe text was updated successfully, but these errors were encountered: