Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Improve reporting of strictProperties #9

Merged
merged 1 commit into from Jan 4, 2012
Jump to file or symbol
Failed to load files and symbols.
+10 −8
Split
View
@@ -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 + '.');
}
}
}