Skip to content
Browse files

Improve reporting of strictProperties

Reports proper environment names and full property path.
  • Loading branch information...
1 parent d8f9b1e commit 9fbc865550db2f64a2c0e95be9b06e6cf00311d8 @cleishm cleishm committed Dec 27, 2011
Showing with 10 additions and 8 deletions.
  1. +10 −8 lib/envious.js
View
18 lib/envious.js
@@ -32,7 +32,7 @@ function envious () {
var env = deepDefaults({}, this[envName]);
if (this.default_env) {
if (options.strictProperties) {
- deepPropertyCompare(env, this[this.default_env]);
+ deepPropertyCompare(env, this[this.default_env], envName, this.default_env);
} else {
env = deepDefaults(env, this[this.default_env]);
}
@@ -71,13 +71,15 @@ function deepDefaults(obj) {
}
-function deepPropertyCompare(obj, default_env) {
- for (var prop in default_env) {
- if (typeof obj[prop] === 'undefined') {
- throw new Error('envious: environment `'+ process.env.NODE_ENV +'` missing property `'+ prop + '` defined in default_env');
- } else if (typeof obj[prop] === 'object'
- && typeof default_env[prop] === 'object') {
- deepPropertyCompare(obj[prop], default_env[prop]);
+function deepPropertyCompare(env1, env2, env1Name, env2Name, propContext) {
+ if (!propContext)
+ propContext = "";
+ for (var prop in env2) {
+ if (typeof env1[prop] === 'undefined') {
+ throw new Error('envious: environment `'+ env1Name +'` missing property `'+ propContext + prop + '` defined in `' + env2Name + '`');
+ } else if (typeof env1[prop] === 'object'
+ && typeof env2[prop] === 'object') {
+ deepPropertyCompare(env1[prop], env2[prop], env1Name, env2Name, propContext + prop + '.');
}
}
}

0 comments on commit 9fbc865

Please sign in to comment.
Something went wrong with that request. Please try again.