Skip to content

Commit e101029

Browse files
committed
Include env var in validation error message
1 parent be350a7 commit e101029

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/convict.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
321321
// attach the value and the property's fullName to the error
322322
e.fullName = fullName;
323323
e.value = x;
324+
325+
if (o.env) {
326+
e.env = o.env;
327+
}
328+
324329
throw e;
325330
}
326331
};
@@ -648,7 +653,13 @@ let convict = function convict(def, opts) {
648653
let e = errors[i];
649654

650655
if (e.fullName) {
651-
err_buf += e.fullName + ': ';
656+
err_buf += e.fullName;
657+
658+
if (e.env) {
659+
err_buf += '[' + e.env + ']';
660+
}
661+
662+
err_buf += ': ';
652663
}
653664
if (e.message) err_buf += e.message;
654665
if (e.value && !sensitive.has(e.fullName)) {

test/cases/env_syntax.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
foo.bar: must be one of the possible values: ["a","b"]: value was "c"
1+
foo.bar[BAR]: must be one of the possible values: ["a","b"]: value was "c"

0 commit comments

Comments
 (0)