import/export: Use Error objects for errors, not strings

This commit is contained in:
Richard Hansen 2021-03-17 18:28:39 -04:00 committed by John McLear
parent 59c167e31b
commit 216aecd433
3 changed files with 6 additions and 7 deletions

View file

@ -102,7 +102,7 @@ exports.doExport = async (req, res, padId, readOnlyId, type) => {
// @TODO no Promise interface for convertors (yet)
await new Promise((resolve, reject) => {
convertor.convertFile(srcFile, destFile, type, (err) => {
err ? reject('convertFailed') : resolve();
err ? reject(new Error('convertFailed')) : resolve();
});
});
}

View file

@ -35,9 +35,7 @@ if (os.type().indexOf('Windows') > -1) {
abiword.stdout.on('data', (data) => { stdoutBuffer += data.toString(); });
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
abiword.on('exit', (code) => {
if (code !== 0) {
return callback(`Abiword died with exit code ${code}`);
}
if (code !== 0) return callback(new Error(`Abiword died with exit code ${code}`));
if (stdoutBuffer !== '') {
console.log(stdoutBuffer);
}
@ -61,13 +59,13 @@ if (os.type().indexOf('Windows') > -1) {
abiword.stderr.on('data', (data) => { stdoutBuffer += data.toString(); });
abiword.on('exit', (code) => {
spawnAbiword();
stdoutCallback(`Abiword died with exit code ${code}`);
stdoutCallback(new Error(`Abiword died with exit code ${code}`));
});
abiword.stdout.on('data', (data) => {
stdoutBuffer += data.toString();
// we're searching for the prompt, cause this means everything we need is in the buffer
if (stdoutBuffer.search('AbiWord:>') !== -1) {
const err = stdoutBuffer.search('OK') !== -1 ? null : stdoutBuffer;
const err = stdoutBuffer.search('OK') !== -1 ? null : new Error(stdoutBuffer);
stdoutBuffer = '';
if (stdoutCallback != null && !firstPrompt) {
stdoutCallback(err);

View file

@ -59,7 +59,8 @@ const doConvertTask = (task, callback) => {
soffice.on('exit', (code) => {
clearTimeout(hangTimeout);
if (code !== 0) {
return callback(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`);
return callback(
new Error(`LibreOffice died with exit code ${code} and message: ${stdoutBuffer}`));
}
callback();
});