From d42f27d4ecb362892c353d1c09bb166dd0db4554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Sat, 30 Nov 2024 10:20:36 +0100 Subject: [PATCH] fix(qseow): Make writing reload script logs to disk more robust Fixes #1296 --- .vscode/launch.json | 70 +++++++++++++++++++------------------- src/lib/qseow/scriptlog.js | 14 ++++++++ 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7f028041..fdb0ea9c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,38 +1,38 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Launch Program", - "program": "${workspaceFolder}/src/butler.js", - // "runtimeVersion": "20", - "runtimeVersion": "18", - // "runtimeVersion": "23", - "cwd": "${workspaceFolder}/src", - "env": { - "NODE_CONFIG_DIR": "${workspaceFolder}/src/config", - "NODE_ENV": "production" - }, - "args": [ - "--configfile", - "config/production.yaml", - // "config/production_template.yaml", - // "--new-relic-account-name", - // "'First NR account'", - // "--new-relic-account-id", - // "ACCOUNTID", - // "--new-relic-api-key", - // "APIKEY", + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/src/butler.js", + // "runtimeVersion": "20", + "runtimeVersion": "18", + // "runtimeVersion": "23", + "cwd": "${workspaceFolder}/src", + "env": { + "NODE_CONFIG_DIR": "${workspaceFolder}/src/config", + "NODE_ENV": "production" + }, + "args": [ + "--configfile", + "config/production.yaml" + // "config/production_template.yaml", + // "--new-relic-account-name", + // "'First NR account'", + // "--new-relic-account-id", + // "ACCOUNTID", + // "--new-relic-api-key", + // "APIKEY", - // "-c", - // "./config/config-gen-api-docs.yaml", - // "--no-qs-connection" - ], - "outFiles": ["${workspaceFolder}/**/*.js"] - } - ] + // "-c", + // "./config/config-gen-api-docs.yaml", + // "--no-qs-connection" + ], + "outFiles": ["${workspaceFolder}/**/*.js"] + } + ] } diff --git a/src/lib/qseow/scriptlog.js b/src/lib/qseow/scriptlog.js index 62cad748..7077546a 100644 --- a/src/lib/qseow/scriptlog.js +++ b/src/lib/qseow/scriptlog.js @@ -318,6 +318,20 @@ export async function failedTaskStoreLogOnDisk(reloadParams) { ); globals.logger.info(`[QSEOW] SCRIPTLOG STORE: Writing failed task script log: ${fileName}`); + + // Do we have a script log to store? + if (!scriptLog.scriptLogFull) { + globals.logger.error('[QSEOW] SCRIPTLOG STORE: A script log should be available, but it is not. Possibly because the QRS API did not return one.'); + return false; + } else if (scriptLog.scriptLogFull.length === 0) { + globals.logger.error('[QSEOW] SCRIPTLOG STORE: A script log is available, but it is empty (zero rows in it).'); + return false; + } else if (scriptLog.scriptLogFull.length < 10) { + globals.logger.warn('[QSEOW] SCRIPTLOG STORE: A script log is available, but it is very short (less than 10 rows).'); + } else { + globals.logger.verbose(`[QSEOW] SCRIPTLOG STORE: Script log is available and has ${scriptLog.scriptLogFull.length} rows.`); + } + fs.writeFileSync(fileName, scriptLog.scriptLogFull.join('\n')); return true; } catch (err) {