Skip to content

Commit

Permalink
Include env var in validation error message
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-booth-qatalog committed Nov 19, 2019
1 parent be350a7 commit 0e285a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/convict.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ function normalizeSchema(name, node, props, fullName, env, argv, sensitive) {
// attach the value and the property's fullName to the error
e.fullName = fullName;
e.value = x;

if (o.env) {
e.env = o.env;
}

throw e;
}
};
Expand Down Expand Up @@ -648,7 +653,13 @@ let convict = function convict(def, opts) {
let e = errors[i];

if (e.fullName) {
err_buf += e.fullName + ': ';
err_buf += e.fullName;

if (e.env) {
err_buf += '[' + e.env + ']';
}

err_buf += ': ';
}
if (e.message) err_buf += e.message;
if (e.value && !sensitive.has(e.fullName)) {
Expand Down
2 changes: 1 addition & 1 deletion test/cases/env_syntax.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foo.bar: must be one of the possible values: ["a","b"]: value was "c"
foo.bar[BAR]: must be one of the possible values: ["a","b"]: value was "c"

0 comments on commit 0e285a1

Please sign in to comment.