From e1010297455967069dfbb24734eab05d22804c07 Mon Sep 17 00:00:00 2001 From: Phil Booth Date: Tue, 19 Nov 2019 13:29:27 +0000 Subject: [PATCH] Include env var in validation error message --- lib/convict.js | 13 ++++++++++++- test/cases/env_syntax.out | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/convict.js b/lib/convict.js index 6c391f54..ee688be7 100644 --- a/lib/convict.js +++ b/lib/convict.js @@ -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; } }; @@ -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)) { diff --git a/test/cases/env_syntax.out b/test/cases/env_syntax.out index 862a53b3..ffbe5926 100644 --- a/test/cases/env_syntax.out +++ b/test/cases/env_syntax.out @@ -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"