From 4c79e3bd0d589aed868b2a46a30fedff2cb56d2e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 9 Apr 2019 15:59:08 +0200 Subject: [PATCH] better error handling when creating rest user fails --- src/rest/creator.js | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/rest/creator.js b/src/rest/creator.js index 35f20badb2..ca414c097c 100644 --- a/src/rest/creator.js +++ b/src/rest/creator.js @@ -14,12 +14,23 @@ See the License for the specific language governing permissions and limitations under the License. */ -const util = require('util'); -const exec = util.promisify(require('child_process').exec); +const {exec} = require('child_process'); const request = require('request-promise-native'); const RestSession = require('./session'); const RestMultiSession = require('./multi'); +function execAsync(command, options) { + return new Promise((resolve, reject) => { + exec(command, options, (error, stdout, stderr) => { + if (error) { + reject(error); + } else { + resolve({stdout, stderr}); + } + }); + }); +} + module.exports = class RestSessionCreator { constructor(synapseSubdir, hsUrl, cwd) { this.synapseSubdir = synapseSubdir; @@ -56,14 +67,7 @@ module.exports = class RestSessionCreator { registerCmd ].join(';'); - try { - await exec(allCmds, {cwd: this.cwd, encoding: 'utf-8'}); - } catch (result) { - // const lines = result.stdout.trim().split('\n'); - // const failureReason = lines[lines.length - 1]; - // const logs = (await exec("tail -n 100 synapse/installations/consent/homeserver.log")).stdout; - throw new Error(`creating user ${username} failed, script output:\n ${result.stdout.trim()}`); - } + await execAsync(allCmds, {cwd: this.cwd, encoding: 'utf-8'}); } async _authenticate(username, password) {