From fa8552c54f28b3638aa169d17bbf172e4b8357a4 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Thu, 9 Jun 2022 11:42:03 +0200 Subject: [PATCH] #4191 Bug fixes --- myvc-push.js | 5 +++- myvc.js | 59 ++++++++++++++++++++++++++++--------------- package.json | 2 +- template/package.json | 2 +- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/myvc-push.js b/myvc-push.js index 5b4cb2b..be77ef5 100644 --- a/myvc-push.js +++ b/myvc-push.js @@ -39,7 +39,7 @@ class Push { const conn = await myvc.dbConnect(); this.conn = conn; - if (opts.commit == null && opts.remote == 'local') + if (opts.remote == 'local') opts.commit = true; // Obtain exclusive lock @@ -557,6 +557,9 @@ class Routine { const type = typeMap[split[1]]; const name = split[2]; + if (split.length !== 3 || !type) + throw new Error(`Wrong routine path for '${path}', check that the sql file is located in the correct directory`); + Object.assign(this, { path, mark: change.mark, diff --git a/myvc.js b/myvc.js index 7bf8b3e..9741ca0 100755 --- a/myvc.js +++ b/myvc.js @@ -9,6 +9,7 @@ const ini = require('ini'); const path = require('path'); const mysql = require('mysql2/promise'); const nodegit = require('nodegit'); +const { networkInterfaces } = require('os'); const camelToSnake = require('./lib').camelToSnake; class MyVC { @@ -49,6 +50,11 @@ class MyVC { }; const opts = this.getopts(baseOpts); + if (opts.debug) { + console.warn('Debug mode enabled.'.yellow); + console.log('Global options:'.magenta, opts); + } + if (opts.version) process.exit(0); @@ -93,12 +99,17 @@ class MyVC { } const commandOpts = this.getopts(allOpts); + if (opts.debug) + console.log('Command options:'.magenta, commandOpts); Object.assign(opts, commandOpts); const operandToOpt = command.usage.operand; if (opts._.length >= 2 && operandToOpt) opts[operandToOpt] = opts._[1]; + if (opts.debug) + console.log('Final options:'.magenta, opts); + if (opts.help) { this.showHelp(command.localOpts, command.usage, commandName); process.exit(0); @@ -145,9 +156,9 @@ class MyVC { } catch (err) { if (err.name == 'Error' && !opts.debug) { console.error('Error:'.gray, err.message.red); - process.exit(1); + console.log(`You can get more details about the error by passing the 'debug' option.`.yellow); } else - throw err; + console.log(err.stack.magenta); } function parameter(parameter, value) { @@ -187,26 +198,33 @@ class MyVC { if (!await fs.pathExists(iniPath)) throw new Error(`Database config file not found: ${iniPath}`); - const iniConfig = ini.parse(await fs.readFile(iniPath, 'utf8')).client; - const dbConfig = { - host: iniConfig.host, - port: iniConfig.port, - user: iniConfig.user, - password: iniConfig.password, - multipleStatements: true, - authPlugins: { - mysql_clear_password() { - return () => iniConfig.password + '\0'; + let dbConfig; + try { + const iniConfig = ini.parse(await fs.readFile(iniPath, 'utf8')).client; + dbConfig = { + host: iniConfig.host, + port: iniConfig.port, + user: iniConfig.user, + password: iniConfig.password, + multipleStatements: true, + authPlugins: { + mysql_clear_password() { + return () => iniConfig.password + '\0'; + } + } + }; + if (iniConfig.ssl_ca) { + dbConfig.ssl = { + ca: await fs.readFile(`${opts.myvcDir}/${iniConfig.ssl_ca}`), + rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined } } - }; - - if (iniConfig.ssl_ca) { - dbConfig.ssl = { - ca: await fs.readFile(`${opts.myvcDir}/${iniConfig.ssl_ca}`), - rejectUnauthorized: iniConfig.ssl_verify_server_cert != undefined - } + } catch(err) { + const newErr = Error(`Cannot process the ini file, check that the syntax is correct: ${iniPath}`); + newErr.stack += `\nCaused by: ${err.stack}`; + throw newErr; } + if (opts.socket) dbConfig.socketPath = '/var/run/mysqld/mysqld.sock'; @@ -255,7 +273,8 @@ class MyVC { ); if (!res.tableExists) { - const structure = await fs.readFile(`${__dirname}/structure.sql`, 'utf8'); + const structure = await fs.readFile( + `${__dirname}/structure.sql`, 'utf8'); await conn.query(structure); } } diff --git a/package.json b/package.json index b06c9c0..d55156d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "myvc", - "version": "1.4.7", + "version": "1.4.8", "author": "Verdnatura Levante SL", "description": "MySQL Version Control", "license": "GPL-3.0", diff --git a/template/package.json b/template/package.json index 7931ba4..37038b4 100644 --- a/template/package.json +++ b/template/package.json @@ -8,6 +8,6 @@ "type": "git" }, "dependencies": { - "myvc": "^1.4.7" + "myvc": "^1.4.8" } }