From 1496afae0d37adb2be3b9ef0d6ac48286525fdec Mon Sep 17 00:00:00 2001 From: SKP Date: Tue, 18 Jun 2019 20:13:26 +0200 Subject: [PATCH] Bug fix: TypeError: Cannot read property 'errors' of undefined --- cyphernodeconf_docker/lib/config.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cyphernodeconf_docker/lib/config.js b/cyphernodeconf_docker/lib/config.js index d1bd9eb..5fa1f73 100644 --- a/cyphernodeconf_docker/lib/config.js +++ b/cyphernodeconf_docker/lib/config.js @@ -48,7 +48,7 @@ module.exports = class Config { return; } this.data = data; - this.data.schema_version = this.data.schema_version || this.data.__version || defaultSchemaVersion; + this.data.schema_version = this.data.schema_version || this.__version || defaultSchemaVersion; this.data.setup_version = this.data.setup_version || this.setup_version; this.data.docker_versions = this.data.docker_versions || this.docker_versions; this.validate(); @@ -83,11 +83,12 @@ module.exports = class Config { } //this.resolveConfigConflicts(); - if( this.data.schema_version !== latestSchemaVersion ) { + const version = this.data.schema_version || this.data.__version || defaultSchemaVersion; + if( version !== latestSchemaVersion ) { // migrate here // create a copy of the old config - fs.copyFileSync( path, path+'-'+this.data.schema_version ); - await this.migrate(this.data.schema_version, latestSchemaVersion ); + fs.copyFileSync( path, path+'-'+version ); + await this.migrate(version, latestSchemaVersion ); // validate again to strip all illegal properties from config with latest version this.validate(); } @@ -102,16 +103,15 @@ module.exports = class Config { } validate() { + const version = this.data.schema_version || this.data.__version; - if( !this.data.schema_version || - !this.validators[this.data.schema_version] || - Object.keys( schemas ).indexOf( this.data.schema_version ) == -1 ) { + if( !version || !this.validators[version] || Object.keys( schemas ).indexOf( version ) == -1 ) { throw "Unknown version in data" } // this will assign default values from the schema - this.valid = this.validators[this.data.schema_version]( this.data ); - this.validateErrors = this.validators[this.data.schema_version].errors; + this.valid = this.validators[version]( this.data ); + this.validateErrors = this.validators[version].errors; } @@ -128,7 +128,8 @@ module.exports = class Config { } async migrate_0_1_0_to_0_2_0() { - if( this.data.schema_version != '0.1.0' ) { + const currentVersion = this.data.schema_version || this.data.__version; + if( currentVersion != '0.1.0' ) { return; }