fixed error reporting problems

This commit is contained in:
Jan Prochazka 2023-02-25 20:25:27 +01:00
parent c817bf5911
commit 0c62349802
4 changed files with 20 additions and 25 deletions

View File

@ -70,15 +70,20 @@ module.exports = {
if (message) {
const json = safeJsonParse(message.message);
if (json) logger.info(json);
if (json) logger.log(json);
else logger.info(message.message);
socket.emit(`runner-info-${runid}`, {
const toEmit = {
time: new Date(),
severity: 'info',
...message,
message: json ? json.msg : message.message,
});
};
if (json && json.level >= 50) {
toEmit.severity = 'error';
}
socket.emit(`runner-info-${runid}`, toEmit);
}
},
@ -125,8 +130,9 @@ module.exports = {
},
}
);
const pipeDispatcher = severity => data =>
this.dispatchMessage(runid, { severity, message: data.toString().trim() });
const pipeDispatcher = severity => data => {
return this.dispatchMessage(runid, { severity, message: data.toString().trim() });
};
byline(subprocess.stdout).on('data', pipeDispatcher('info'));
byline(subprocess.stderr).on('data', pipeDispatcher('error'));

View File

@ -11,7 +11,7 @@ async function runScript(func) {
await func();
process.exit(0);
} catch (err) {
logger.error('Error running script', err);
logger.error({ err }, `Error running script: ${err.message}`);
process.exit(1);
}
}

View File

@ -255,7 +255,7 @@ export class DataDuplicator {
);
}
} catch (err) {
logger.error({ err }, 'Failed duplicator job, rollbacking');
logger.error({ err }, `Failed duplicator job, rollbacking. ${err.message}`);
await runCommandOnDriver(this.pool, this.driver, dmp => dmp.rollbackTransaction());
return;
}

View File

@ -14,23 +14,12 @@ export function createAsyncWriteStream(stream, options: AsyncWriteStreamOptions)
});
writable._write = async (chunk, encoding, callback) => {
await options.processItem(chunk);
// const { sql, id, newIdSql } = chunk;
// if (_isArray(sql)) {
// for (const item of sql) await driver.query(pool, item, { discardResult: true });
// } else {
// await driver.query(pool, sql, { discardResult: true });
// }
// if (newIdSql) {
// const res = await driver.query(pool, newIdSql);
// const resId = Object.entries(res?.rows?.[0])?.[0]?.[1];
// if (options?.mapResultId) {
// options?.mapResultId(id, resId as string);
// }
// }
callback();
try {
await options.processItem(chunk);
callback(null);
} catch (err) {
callback(err);
}
};
// writable._final = async callback => {