diff --git a/src/__tests__/bookmark_get_jwt.test.js b/src/__tests__/bookmark_get_jwt.test.js index 48b8244..c98df76 100644 --- a/src/__tests__/bookmark_get_jwt.test.js +++ b/src/__tests__/bookmark_get_jwt.test.js @@ -58,124 +58,125 @@ describe('get in-app bookmarks (jwt auth)', () => { options.idType = 'id'; options.outputFormat = 'json'; + console.log(options) const result = await getBookmark(options); // Result should be false expect(result).toBe(false); }); - /** - * All bookmarks in app, JSON output - * No bookmarks exist in app that exist - * - * --app-id - * --id-type id - * --output-format json - */ - test('get all bookmarks from app that has no bookmarks in it', async () => { - options.appId = appIdExistsNoBookmarks1; - options.idType = 'id'; - options.outputFormat = 'json'; - - const result = await getBookmark(options); - - // Result should be empty array - expect(result).toStrictEqual([]); - }); - - /** - * All bookmarks in app, JSON output - * App has 2 bookmarks - * - * --app-id - * --id-type id - * --output-format json - */ - test('get all bookmarks from app that has bookmarks in it', async () => { - options.appId = appIdExistsHasBookmarks1; - options.idType = 'id'; - options.outputFormat = 'json'; - - const result = await getBookmark(options); - - // Result should be array with 2 bookmarks - expect(result.length).toBe(2); - - // Verify that the bookmarks have the correct IDs - expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); - expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); - }); - - /** - * All bookmarks in app, table output - * App has 2 bookmarks - * - * --app-id - * --id-type id - * --output-format json - */ - test('get all bookmarks from app that has bookmarks in it', async () => { - options.appId = appIdExistsHasBookmarks1; - options.idType = 'id'; - options.outputFormat = 'table'; - - const result = await getBookmark(options); - - // Result should be array with 2 bookmarks - expect(result.length).toBe(2); - - // Verify that the bookmarks have the correct IDs - expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); - expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); - }); - - /** - * Get 2 specific bookmarks (based on ID) from app, JSON output - * App has 2 bookmarks - * - * --app-id - * --id-type id - * --output-format json - * --bookmark [, ] - */ - test('get 2 specific bookmarks from app that has bookmarks in it', async () => { - options.appId = appIdExistsHasBookmarks1; - options.idType = 'id'; - options.outputFormat = 'json'; - options.bookmark = [appIdExistsHasBookmarks1Bookmark1, appIdExistsHasBookmarks1Bookmark2]; - - const result = await getBookmark(options); - - // Result should be array with 2 bookmarks - expect(result.length).toBe(2); - - // Verify that the bookmarks have the correct IDs - expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); - expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); - }); - - /** - * Get 2 specific bookmarks (based on name) from app, JSON output - * App has 2 bookmarks - * - * --app-id - * --id-type name - * --output-format json - * --bookmark [, ] - */ - test('get 2 specific bookmarks from app that has bookmarks in it', async () => { - options.appId = appIdExistsHasBookmarks1; - options.idType = 'name'; - options.outputFormat = 'json'; - options.bookmark = ['Bookmark 1', 'Bookmark 2']; - - const result = await getBookmark(options); - - // Result should be array with 2 bookmark - expect(result.length).toBe(2); - - // Verify that the bookmarks have the correct IDs - expect(result[0].qMeta.title).toBe('Bookmark 1'); - expect(result[1].qMeta.title).toBe('Bookmark 2'); - }); + // /** + // * All bookmarks in app, JSON output + // * No bookmarks exist in app that exist + // * + // * --app-id + // * --id-type id + // * --output-format json + // */ + // test('get all bookmarks from app that has no bookmarks in it', async () => { + // options.appId = appIdExistsNoBookmarks1; + // options.idType = 'id'; + // options.outputFormat = 'json'; + + // const result = await getBookmark(options); + + // // Result should be empty array + // expect(result).toStrictEqual([]); + // }); + + // /** + // * All bookmarks in app, JSON output + // * App has 2 bookmarks + // * + // * --app-id + // * --id-type id + // * --output-format json + // */ + // test('get all bookmarks from app that has bookmarks in it', async () => { + // options.appId = appIdExistsHasBookmarks1; + // options.idType = 'id'; + // options.outputFormat = 'json'; + + // const result = await getBookmark(options); + + // // Result should be array with 2 bookmarks + // expect(result.length).toBe(2); + + // // Verify that the bookmarks have the correct IDs + // expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); + // expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); + // }); + + // /** + // * All bookmarks in app, table output + // * App has 2 bookmarks + // * + // * --app-id + // * --id-type id + // * --output-format json + // */ + // test('get all bookmarks from app that has bookmarks in it', async () => { + // options.appId = appIdExistsHasBookmarks1; + // options.idType = 'id'; + // options.outputFormat = 'table'; + + // const result = await getBookmark(options); + + // // Result should be array with 2 bookmarks + // expect(result.length).toBe(2); + + // // Verify that the bookmarks have the correct IDs + // expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); + // expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); + // }); + + // /** + // * Get 2 specific bookmarks (based on ID) from app, JSON output + // * App has 2 bookmarks + // * + // * --app-id + // * --id-type id + // * --output-format json + // * --bookmark [, ] + // */ + // test('get 2 specific bookmarks from app that has bookmarks in it', async () => { + // options.appId = appIdExistsHasBookmarks1; + // options.idType = 'id'; + // options.outputFormat = 'json'; + // options.bookmark = [appIdExistsHasBookmarks1Bookmark1, appIdExistsHasBookmarks1Bookmark2]; + + // const result = await getBookmark(options); + + // // Result should be array with 2 bookmarks + // expect(result.length).toBe(2); + + // // Verify that the bookmarks have the correct IDs + // expect(result[0].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark1); + // expect(result[1].qInfo.qId).toBe(appIdExistsHasBookmarks1Bookmark2); + // }); + + // /** + // * Get 2 specific bookmarks (based on name) from app, JSON output + // * App has 2 bookmarks + // * + // * --app-id + // * --id-type name + // * --output-format json + // * --bookmark [, ] + // */ + // test('get 2 specific bookmarks from app that has bookmarks in it', async () => { + // options.appId = appIdExistsHasBookmarks1; + // options.idType = 'name'; + // options.outputFormat = 'json'; + // options.bookmark = ['Bookmark 1', 'Bookmark 2']; + + // const result = await getBookmark(options); + + // // Result should be array with 2 bookmark + // expect(result.length).toBe(2); + + // // Verify that the bookmarks have the correct IDs + // expect(result[0].qMeta.title).toBe('Bookmark 1'); + // expect(result[1].qMeta.title).toBe('Bookmark 2'); + // }); }); diff --git a/src/__tests__/script_get_jwt.test.js b/src/__tests__/script_get_jwt.test.js index 3709957..301472c 100644 --- a/src/__tests__/script_get_jwt.test.js +++ b/src/__tests__/script_get_jwt.test.js @@ -21,7 +21,7 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 120000; // 2 minut jest.setTimeout(defaultTestTimeout); // Get app script -describe('get app script (cert auth)', () => { +describe('get app script (jwt auth)', () => { options.authType = 'jwt'; options.port = '443'; options.virtualProxy = 'jwt'; diff --git a/src/__tests__/task_cert.test.js b/src/__tests__/task_cert.test.js index 858f44a..c6756c9 100644 --- a/src/__tests__/task_cert.test.js +++ b/src/__tests__/task_cert.test.js @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu jest.setTimeout(defaultTestTimeout); // Mock logger -// global.console = { -// log: jest.fn(), -// info: jest.fn(), -// error: jest.fn(), -// }; +global.console = { + log: jest.fn(), + info: jest.fn(), + error: jest.fn(), +}; // Define existing and non-existing tasks const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9'; @@ -79,20 +79,20 @@ describe('getTaskByName: Get task by name (cert auth)', () => { }); }); -// Get task by ID -describe('getTaskById: Get task by ID (cert auth)', () => { - test('no matching task', async () => { - const result = await getTaskById(nonExistingTaskId, options); - expect(result).toEqual(false); - }); - - test('1 matching task', async () => { - const result = await getTaskById(existingTaskId, options); - expect(result.id).toEqual(existingTaskId); - }); - - test('no task id provided', async () => { - const result = await getTaskById('', options); - expect(result).toEqual(false); - }); -}); +// // Get task by ID +// describe('getTaskById: Get task by ID (cert auth)', () => { +// test('no matching task', async () => { +// const result = await getTaskById(nonExistingTaskId, options); +// expect(result).toEqual(false); +// }); + +// test('1 matching task', async () => { +// const result = await getTaskById(existingTaskId, options); +// expect(result.id).toEqual(existingTaskId); +// }); + +// test('no task id provided', async () => { +// const result = await getTaskById('', options); +// expect(result).toEqual(false); +// }); +// }); diff --git a/src/__tests__/task_jwt.test.js b/src/__tests__/task_jwt.test.js index 858f44a..986b387 100644 --- a/src/__tests__/task_jwt.test.js +++ b/src/__tests__/task_jwt.test.js @@ -23,11 +23,11 @@ const defaultTestTimeout = process.env.CTRL_Q_TEST_TIMEOUT || 600000; // 10 minu jest.setTimeout(defaultTestTimeout); // Mock logger -// global.console = { -// log: jest.fn(), -// info: jest.fn(), -// error: jest.fn(), -// }; +global.console = { + log: jest.fn(), + info: jest.fn(), + error: jest.fn(), +}; // Define existing and non-existing tasks const existingTaskId = 'e9100e69-4e8e-414b-bf88-10a1110c43a9'; diff --git a/src/ctrl-q.js b/src/ctrl-q.js index bd8f1dc..9349e02 100644 --- a/src/ctrl-q.js +++ b/src/ctrl-q.js @@ -1,27 +1,27 @@ import { Command, Option } from 'commander'; import { logger, appVersion, setLoggingLevel, setCliOptions } from './globals.js'; -import logStartupInfo from './lib/util/log.js'; +import { catchLog, logStartupInfo } from './lib/util/log.js'; // const { createUserActivityCustomProperty } = require('./lib/createuseractivitycp'); -import { getMasterDimension } from './lib/cmd/getdim.js'; - -import { deleteMasterDimension } from './lib/cmd/deletedim.js'; -import { getMasterMeasure } from './lib/cmd/getmeasure.js'; -import { deleteMasterMeasure } from './lib/cmd/deletemeasure.js'; -import { getVariable } from './lib/cmd/getvariable.js'; -import { deleteVariable } from './lib/cmd/deletevariable.js'; -import { getBookmark } from './lib/cmd/getbookmark.js'; -import { importMasterItemFromFile } from './lib/cmd/import-masteritem-excel.js'; -import { scrambleField } from './lib/cmd/scramblefield.js'; -import { getScript } from './lib/cmd/getscript.js'; -import { getTask } from './lib/cmd/gettask.js'; -import { setTaskCustomProperty } from './lib/cmd/settaskcp.js'; -import { importTaskFromFile } from './lib/cmd/importtask.js'; -import { importAppFromFile } from './lib/cmd/importapp.js'; -import { exportAppToFile } from './lib/cmd/exportapp.js'; -import { jest, testConnection } from './lib/cmd/testconnection.js'; -import { visTask } from './lib/cmd/vistask.js'; +import getMasterDimension from './lib/cmd/getdim.js'; + +import deleteMasterDimension from './lib/cmd/deletedim.js'; +import getMasterMeasure from './lib/cmd/getmeasure.js'; +import deleteMasterMeasure from './lib/cmd/deletemeasure.js'; +import getVariable from './lib/cmd/getvariable.js'; +import deleteVariable from './lib/cmd/deletevariable.js'; +import getBookmark from './lib/cmd/getbookmark.js'; +import importMasterItemFromFile from './lib/cmd/import-masteritem-excel.js'; +import scrambleField from './lib/cmd/scramblefield.js'; +import getScript from './lib/cmd/getscript.js'; +import getTask from './lib/cmd/gettask.js'; +import setTaskCustomProperty from './lib/cmd/settaskcp.js'; +import importTaskFromFile from './lib/cmd/importtask.js'; +import importAppFromFile from './lib/cmd/importapp.js'; +import exportAppToFile from './lib/cmd/exportapp.js'; +import testConnection from './lib/cmd/testconnection.js'; +import visTask from './lib/cmd/vistask.js'; import { sharedParamAssertOptions, @@ -128,7 +128,7 @@ const program = new Command(); masterItemImportAssertOptions(options); importMasterItemFromFile(options); } catch (err) { - logger.error(`IMPORT EXCEL: ${err}`); + catchLog('IMPORT EXCEL', err); } }) .addOption( @@ -632,7 +632,7 @@ const program = new Command(); taskImportAssertOptions(options); importTaskFromFile(options); } catch (err) { - logger.error(`IMPORT TASK 1: ${err}`); + catchLog('IMPORT TASK 1', err); } }) .addOption( @@ -684,7 +684,7 @@ const program = new Command(); appImportAssertOptions(options); importAppFromFile(options); } catch (err) { - logger.error(`IMPORT APP: ${err}`); + catchLog('IMPORT APP', err); } }) .addOption( @@ -727,7 +727,7 @@ const program = new Command(); await appExportAssertOptions(options); exportAppToFile(options); } catch (err) { - logger.error(`EXPORT APP: ${err}`); + catchLog('EXPORT APP', err); } }) .addOption( @@ -788,7 +788,7 @@ const program = new Command(); await sharedParamAssertOptions(options); testConnection(options); } catch (err) { - logger.error(`CONNECTION TEST: ${err}`); + catchLog('CONNECTION TEST', err); } }) .addOption( diff --git a/src/globals.js b/src/globals.js index 0d1794c..cfbdccf 100644 --- a/src/globals.js +++ b/src/globals.js @@ -80,7 +80,19 @@ export const verifyFileExists = async (file) => { await Fs.stat(file); exists = true; } catch (err) { - logger.error(`Error while checking if file ${file} exists: ${JSON.stringify(err, null, 2)}`); + if (isPkg) { + if (err.message) { + logger.error(`Error while checking if file ${file} exists: ${err.message}`); + } else { + logger.error(`Error while checking if file ${file} exists: ${err}`); + } + } else if (err.stack) { + logger.error(`Error while checking if file ${file} exists: ${err.stack}`); + } else if (err.message) { + logger.error(`Error while checking if file ${file} exists: ${err.message}`); + } else { + logger.error(`Error while checking if file ${file} exists: ${err}`); + } } return exists; diff --git a/src/lib/app/class_allapps.js b/src/lib/app/class_allapps.js index 476fd2a..35f8c0d 100644 --- a/src/lib/app/class_allapps.js +++ b/src/lib/app/class_allapps.js @@ -6,13 +6,14 @@ import fs from 'fs/promises'; import fs2 from 'fs'; import { v4 as uuidv4, validate } from 'uuid'; import yesno from 'yesno'; -import { logger, execPath, mergeDirFilePath, verifyFileExists, sleep } from '../../globals.js'; +import { logger, execPath, mergeDirFilePath, verifyFileExists, sleep, isPkg } from '../../globals.js'; import setupQRSConnection from '../util/qrs.js'; import { getAppColumnPosFromHeaderRow } from '../util/lookups.js'; import QlikSenseApp from './class_app.js'; import { getTagIdByName } from '../util/tag.js'; import { getAppById, deleteAppById } from '../util/app.js'; import { getCustomPropertyDefinitionByName, doesCustomPropertyValueExist } from '../util/customproperties.js'; +import { catchLog } from '../util/log.js'; class QlikSenseApps { // eslint-disable-next-line no-useless-constructor @@ -35,12 +36,7 @@ class QlikSenseApps { // Map that will connect app counter from Excel file with ID an app gets after import to QSEoW this.appCounterIdMap = new Map(); } catch (err) { - logger.error(`QS APP: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`QS APP:\n ${err.stack}`); - } + catchLog(`INIT QS APP`, err); } } @@ -157,13 +153,7 @@ class QlikSenseApps { return apps; } catch (err) { - // console.log(err) - logger.error(`GET QS APP 2: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`GET QS APP 2:\n ${err.stack}`); - } + catchLog(`GET QS APP 2`, err); return false; } @@ -676,12 +666,7 @@ class QlikSenseApps { ); return false; } catch (err) { - logger.error(`UPDATE UPLOADED APP: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`UPDATE UPLOADED APP:\n ${err.stack}`); - } + catchLog(`UPDATE UPLOADED APP`, err); return false; } @@ -763,12 +748,8 @@ class QlikSenseApps { return result; } catch (err) { - logger.error(`(${appCounter}) PUBLISH APP publish-replace: Failed: ${err}`); + catchLog(`PUBLISH APP publish-replace`, err); - // Show stack trace if available - if (err?.stack) { - logger.error(`(${appCounter}) PUBLISH APP publish-replace:\n ${err.stack}`); - } return { res: false, publishedApp: null }; } } @@ -795,12 +776,7 @@ class QlikSenseApps { return result; } catch (err) { - logger.error(`(${appCounter}) PUBLISH APP publish-another: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`(${appCounter}) PUBLISH APP publish-another:\n ${err.stack}`); - } + catchLog(`PUBLISH APP publish-another`, err); return { res: false, publishedApp: null }; } @@ -864,12 +840,7 @@ class QlikSenseApps { return result; } catch (err) { - logger.error(`(${appCounter}) PUBLISH APP delete-publish: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`(${appCounter}) PUBLISH APP delete-publish:\n ${err.stack}`); - } + catchLog(`PUBLISH APP delete-publish`, err); return { res: false, publishedApp: null }; } @@ -916,12 +887,7 @@ class QlikSenseApps { return false; } catch (err) { - logger.error(`PUBLISH APP NORMAL: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`PUBLISH APP NORMAL:\n ${err.stack}`); - } + catchLog(`PUBLISH APP NORMAL`, err); return false; } @@ -966,12 +932,7 @@ class QlikSenseApps { return false; } catch (err) { - logger.error(`PUBLISH APP REPLACE: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`PUBLISH APP REPLACE:\n ${err.stack}`); - } + catchLog(`PUBLISH APP REPLACE`, err); return false; } @@ -1033,12 +994,7 @@ class QlikSenseApps { logger.debug(`CHECK IF APP EXISTS IN STREAM: App "${appName}" does not exist in stream "${streamName}"`); return 0; } catch (err) { - logger.error(`CHECK IF APP EXISTS IN STREAM: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`CHECK IF APP EXISTS IN STREAM:\n ${err.stack}`); - } + catchLog(`CHECK IF APP EXISTS IN STREAM`, err); return false; } @@ -1094,12 +1050,7 @@ class QlikSenseApps { logger.error(`GET APP IN STREAM: Something went wrong`); return false; } catch (err) { - logger.error(`GET APP IN STREAM: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`GET APP IN STREAM:\n ${err.stack}`); - } + catchLog(`GET APP IN STREAM`, err); return false; } @@ -1197,12 +1148,7 @@ class QlikSenseApps { return false; } catch (err) { - logger.error(`CHECK IF STREAM EXISTS: Failed: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`CHECK IF STREAM EXISTS:\n ${err.stack}`); - } + catchLog(`CHECK IF STREAM EXISTS`, err); return false; } @@ -1301,12 +1247,7 @@ class QlikSenseApps { return false; } catch (err) { - logger.error(`CREATE RELOAD TASK IN QSEOW 2: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`CREATE RELOAD TASK IN QSEOW 2:\n ${err.stack}`); - } + catchLog(`UPLOAD APP TO QSEOW`, err); return false; } @@ -1350,12 +1291,7 @@ class QlikSenseApps { logger.warn(`Export app step 1 failed: [${result.status}] ${result.statusText}`); return false; } catch (err) { - logger.error(`[${err}] Export app step 1`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`[${err}] Export app step 1:\n ${err.stack}`); - } + catchLog(`EXPORT APP STEP 1`, err); return false; } diff --git a/src/lib/cmd/createdim.js b/src/lib/cmd/createdim.js index a2c2bc2..f078d37 100644 --- a/src/lib/cmd/createdim.js +++ b/src/lib/cmd/createdim.js @@ -1,6 +1,7 @@ import enigma from 'enigma.js'; import setupEnigmaConnection from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; /** * @@ -251,7 +252,7 @@ const createMasterDimension = async (options) => { logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); } } catch (err) { - logger.error(`Error destroying session object for master dimenions`); + catchLog('Error creating master dimension', err); } }; diff --git a/src/lib/cmd/createuseractivitycp.js b/src/lib/cmd/createuseractivitycp.js index 1fa5665..be0673a 100644 --- a/src/lib/cmd/createuseractivitycp.js +++ b/src/lib/cmd/createuseractivitycp.js @@ -10,6 +10,7 @@ import { getUserActivityUser, getUsersLastActivity, } from './useractivity.js'; +import { catchLog } from '../util/log.js'; const _MS_PER_DAY = 1000 * 60 * 60 * 24; @@ -66,7 +67,7 @@ const createUserActivityCustomProperty = async (options) => { result = await qrsInteractInstance.Get(`custompropertydefinition/full?filter=name eq '${options.customPropertyName}'`); } catch (err) { // Return error msg - logger.error(`USER ACTIVITY CP: Error getting user activity custom property: ${err}`); + catchLog(`USER ACTIVITY CP: Error getting user activity custom property`, err); } if (result.statusCode === 200) { @@ -110,7 +111,7 @@ const createUserActivityCustomProperty = async (options) => { 'json' ); } catch (err) { - logger.error(`USER ACTIVITY CP: Error creating user activity custom property: ${err}`); + catchLog(`USER ACTIVITY CP: Error creating user activity custom property`, err); } if (result.statusCode === 201) { @@ -201,14 +202,14 @@ const createUserActivityCustomProperty = async (options) => { 'json' ); } catch (err) { - logger.error(`USER ACTIVITY CP: Error creating user activity custom property: ${err}`); + catchLog(`USER ACTIVITY CP: Error creating user activity custom property`, err); } } logger.verbose(`USER ACTIVITY CP: Assigned activity buckets to users via custom property ${options.customPropertyName}`); } } catch (err) { // Return error msg - logger.error(`USER ACTIVITY CP: ${err}`); + catchLog(`USER ACTIVITY CP: Error creating user activity custom property`, err); } }; diff --git a/src/lib/cmd/deletedim.js b/src/lib/cmd/deletedim.js index 1675e7d..91761b6 100644 --- a/src/lib/cmd/deletedim.js +++ b/src/lib/cmd/deletedim.js @@ -1,6 +1,7 @@ import enigma from 'enigma.js'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; // Variable to keep track of how many dimensions have been deleted let deleteCount = 0; @@ -31,7 +32,7 @@ const deleteMasterDimension = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -42,7 +43,7 @@ const deleteMasterDimension = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -51,7 +52,7 @@ const deleteMasterDimension = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -151,7 +152,7 @@ const deleteMasterDimension = async (options) => { logger.error(`Error destroying session object for master dimenions`); } } catch (err) { - logger.error(err.stack); + catchLog('Error in deleteMasterDimension', err); } }; diff --git a/src/lib/cmd/deletemeasure.js b/src/lib/cmd/deletemeasure.js index aa64dee..6bd61c4 100644 --- a/src/lib/cmd/deletemeasure.js +++ b/src/lib/cmd/deletemeasure.js @@ -1,6 +1,7 @@ import enigma from 'enigma.js'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; // Variable to keep track of how many measures have been deleted let deleteCount = 0; @@ -31,7 +32,7 @@ const deleteMasterMeasure = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -42,7 +43,7 @@ const deleteMasterMeasure = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -51,7 +52,7 @@ const deleteMasterMeasure = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -145,7 +146,7 @@ const deleteMasterMeasure = async (options) => { logger.error(`Error destroying session object for master dimenions`); } } catch (err) { - logger.error(err.stack); + catchLog('Error in deleteMasterMeasure', err); } }; diff --git a/src/lib/cmd/deletevariable.js b/src/lib/cmd/deletevariable.js index 9f07971..a25d139 100644 --- a/src/lib/cmd/deletevariable.js +++ b/src/lib/cmd/deletevariable.js @@ -5,6 +5,7 @@ import enigma from 'enigma.js'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { getApps } from '../util/app.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; /** * @@ -33,7 +34,7 @@ const deleteVariable = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -44,7 +45,7 @@ const deleteVariable = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -53,7 +54,7 @@ const deleteVariable = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -159,7 +160,7 @@ const deleteVariable = async (options) => { logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); } } catch (err) { - logger.error(`DELETE VARIABLE: ${err.stack}`); + catchLog('Error in deleteVariable', err); } }; diff --git a/src/lib/cmd/exportapp.js b/src/lib/cmd/exportapp.js index 7f84e30..79d64c3 100644 --- a/src/lib/cmd/exportapp.js +++ b/src/lib/cmd/exportapp.js @@ -5,6 +5,7 @@ import yesno from 'yesno'; import { logger, setLoggingLevel, isPkg, execPath, mergeDirFilePath, verifyFileExists, isNumeric, sleep } from '../../globals.js'; import QlikSenseApps from '../app/class_allapps.js'; +import { catchLog } from '../util/log.js'; const exportAppToFile = async (options) => { try { @@ -151,7 +152,7 @@ const exportAppToFile = async (options) => { } return true; } catch (err) { - logger.error(`EXPORT APP: ${err.stack}`); + catchLog('Export app', err); } }; diff --git a/src/lib/cmd/getbookmark.js b/src/lib/cmd/getbookmark.js index 0be2716..09fb95c 100644 --- a/src/lib/cmd/getbookmark.js +++ b/src/lib/cmd/getbookmark.js @@ -2,6 +2,7 @@ import enigma from 'enigma.js'; import { table } from 'table'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; const consoleTableConfig = { border: { @@ -59,20 +60,7 @@ const getBookmark = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - // Show more brief info if running as a stand-alone binary. - if (isPkg) { - if (err.message) { - logger.error(`Error creating session to server ${options.host}: ${err.message}`); - } else { - logger.error(`Error creating session to server ${options.host}: ${err}`); - } - } else if (err.stack) { - logger.error(`Error creating session to server ${options.host}: ${err.stack}`); - } else if (err.message) { - logger.error(`Error creating session to server ${options.host}: ${err.message}`); - } else { - logger.error(`Error creating session to server ${options.host}: ${err}`); - } + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -83,19 +71,7 @@ const getBookmark = async (options) => { try { global = await session.open(); } catch (err) { - if (isPkg) { - if (err.message) { - logger.error(`Error opening session to server ${options.host}: ${err.message}`); - } else { - logger.error(`Error opening session to server ${options.host}: ${err}`); - } - } else if (err.stack) { - logger.error(`Error opening session to server ${options.host}: ${err.stack}`); - } else if (err.message) { - logger.error(`Error opening session to server ${options.host}: ${err.message}`); - } else { - logger.error(`Error opening session to server ${options.host}: ${err}`); - } + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -104,19 +80,7 @@ const getBookmark = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - if (isPkg) { - if (err.message) { - logger.error(`Error getting engine version from server ${options.host}: ${err.message}`); - } else { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); - } - } else if (err.stack) { - logger.error(`Error getting engine version from server ${options.host}: ${err.stack}`); - } else if (err.message) { - logger.error(`Error getting engine version from server ${options.host}: ${err.message}`); - } else { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); - } + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -240,19 +204,7 @@ const getBookmark = async (options) => { logger.error(`Error destroying session object for bookmarks`); return false; } catch (err) { - if (isPkg) { - if (err.message) { - logger.error(`Error getting bookmarks in app ${options.appId} on host ${options.host}: ${err.message}`); - } else { - logger.error(`Error getting bookmarks in app ${options.appId} on host ${options.host}: ${err}`); - } - } else if (err.stack) { - logger.error(`Error getting bookmarks in app ${options.appId} on host ${options.host}: ${err.stack}`); - } else if (err.message) { - logger.error(`Error getting bookmarks in app ${options.appId} on host ${options.host}: ${err.message}`); - } else { - logger.error(`Error getting bookmarks in app ${options.appId} on host ${options.host}: ${err}`); - } + catchLog(`Error getting bookmarks in app ${options.appId} on host ${options.host}`, err); // Is there an active session? Close it if so. if (session !== undefined) { diff --git a/src/lib/cmd/getdim.js b/src/lib/cmd/getdim.js index 89c72c8..c62d91e 100644 --- a/src/lib/cmd/getdim.js +++ b/src/lib/cmd/getdim.js @@ -5,6 +5,7 @@ import enigma from 'enigma.js'; import { table } from 'table'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; const consoleTableConfig = { border: { @@ -62,7 +63,7 @@ const getMasterDimension = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -73,7 +74,7 @@ const getMasterDimension = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -82,7 +83,7 @@ const getMasterDimension = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -164,7 +165,7 @@ const getMasterDimension = async (options) => { const colorMapRefLayout = await genericColorMapRefModel.getLayout(); dimension.colorMap = colorMapRefLayout.colorMap; } catch (err) { - logger.error(err.stack); + catchLog(`Error getting color map for dimension ${dimension.qInfo.qId}`, err); } } } @@ -266,8 +267,7 @@ const getMasterDimension = async (options) => { logger.error(`Error destroying session object for master dimenions`); } } catch (err) { - logger.error(err); - logger.error(err.stack); + catchLog(`Error getting master dimensions`, err); } }; diff --git a/src/lib/cmd/getmeasure.js b/src/lib/cmd/getmeasure.js index ec54e88..d530ab0 100644 --- a/src/lib/cmd/getmeasure.js +++ b/src/lib/cmd/getmeasure.js @@ -4,6 +4,7 @@ import enigma from 'enigma.js'; import { table } from 'table'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; const consoleTableConfig = { border: { @@ -60,7 +61,7 @@ const getMasterMeasure = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -71,7 +72,7 @@ const getMasterMeasure = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -80,7 +81,7 @@ const getMasterMeasure = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -240,7 +241,7 @@ const getMasterMeasure = async (options) => { logger.error(`Error destroying session object for master measures`); } } catch (err) { - logger.error(err.stack); + catchLog('Error in getMasterMeasure', err); } }; diff --git a/src/lib/cmd/getscript.js b/src/lib/cmd/getscript.js index 1d5fec5..affca08 100644 --- a/src/lib/cmd/getscript.js +++ b/src/lib/cmd/getscript.js @@ -1,6 +1,7 @@ import enigma from 'enigma.js'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; /** * @@ -28,7 +29,7 @@ const getScript = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -39,7 +40,7 @@ const getScript = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -48,7 +49,7 @@ const getScript = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -82,7 +83,7 @@ const getScript = async (options) => { appScript: appScript.qScript, }; } catch (err) { - logger.error(`GET SCRIPT: ${err}`); + catchLog('Error in getScript', err); } }; diff --git a/src/lib/cmd/gettask.js b/src/lib/cmd/gettask.js index 038470a..dc23b00 100644 --- a/src/lib/cmd/gettask.js +++ b/src/lib/cmd/gettask.js @@ -8,6 +8,7 @@ import { logger, setLoggingLevel, isPkg, execPath, verifyFileExists } from '../. import QlikSenseTasks from '../task/class_alltasks.js'; import { mapEventType, mapIncrementOption, mapDaylightSavingTime, mapRuleState } from '../util/lookups.js'; import { getTagsFromQseow } from '../util/tag.js'; +import { catchLog } from '../util/log.js'; const consoleTableConfig = { border: { @@ -769,7 +770,7 @@ const getTask = async (options) => { } return returnValue; } catch (err) { - logger.error(`GET TASK: ${err.stack}`); + catchLog('Get task', err); return false; } }; diff --git a/src/lib/cmd/getvariable.js b/src/lib/cmd/getvariable.js index 6a61421..e871b48 100644 --- a/src/lib/cmd/getvariable.js +++ b/src/lib/cmd/getvariable.js @@ -6,6 +6,7 @@ import { table } from 'table'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { getApps } from '../util/app.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; const consoleTableConfig = { border: { @@ -63,7 +64,7 @@ const getVariable = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -74,7 +75,7 @@ const getVariable = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -83,7 +84,7 @@ const getVariable = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -247,7 +248,7 @@ const getVariable = async (options) => { logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); } } catch (err) { - logger.error(`GET VARIABLE: ${err.stack}`); + catchLog(`Error in getVariable`, err); } }; diff --git a/src/lib/cmd/import-masteritem-excel.js b/src/lib/cmd/import-masteritem-excel.js index bb2d15f..4cec13a 100644 --- a/src/lib/cmd/import-masteritem-excel.js +++ b/src/lib/cmd/import-masteritem-excel.js @@ -6,6 +6,7 @@ import xlsx from 'node-xlsx'; import { v4 as uuidCreate } from 'uuid'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath, verifyFileExists, sleep } from '../../globals.js'; +import { catchLog } from '../util/log.js'; let importCount = 0; @@ -206,7 +207,7 @@ const updateDimension = async ( [existingColorMapModel] = await Promise.all([existingColorMapPromise]); existingColorMapLayout = await existingColorMapModel.getLayout(); } catch (err) { - logger.verbose(`No per-value color map exists for existing dimension "${existingDimensionLayout.qMeta.title}"`); + catchLog(`No per-value color map exists for existing dimension "${existingDimensionLayout.qMeta.title}"`, err); } // Do we have new per-value color data? @@ -723,7 +724,7 @@ const createMasterItems = async (masterItemDefs, options, colPos, existingMeasur try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -1022,7 +1023,7 @@ const importMasterItemFromExcel = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -1033,7 +1034,7 @@ const importMasterItemFromExcel = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -1042,7 +1043,7 @@ const importMasterItemFromExcel = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -1138,7 +1139,7 @@ const importMasterItemFromExcel = async (options) => { logger.error(`Error closing session for app ${options.appId} on host ${options.host}`); } } catch (err) { - logger.error(err.stack); + catchLog('Error importing master items from Excel file', err); } }; diff --git a/src/lib/cmd/importapp.js b/src/lib/cmd/importapp.js index 3aca61d..7ad908e 100644 --- a/src/lib/cmd/importapp.js +++ b/src/lib/cmd/importapp.js @@ -7,6 +7,7 @@ import QlikSenseApps from '../app/class_allapps.js'; import { getAppColumnPosFromHeaderRow } from '../util/lookups.js'; import { getTagsFromQseow } from '../util/tag.js'; import { getCustomPropertiesFromQseow } from '../util/customproperties.js'; +import { catchLog } from '../util/log.js'; const importAppFromFile = async (options) => { try { @@ -82,7 +83,7 @@ const importAppFromFile = async (options) => { } return false; } catch (err) { - logger.error(`IMPORT APP: ${err.stack}`); + catchLog('IMPORT APP', err); return false; } }; diff --git a/src/lib/cmd/importtask.js b/src/lib/cmd/importtask.js index aadee57..fc4b4a6 100644 --- a/src/lib/cmd/importtask.js +++ b/src/lib/cmd/importtask.js @@ -14,6 +14,7 @@ import QlikSenseApps from '../app/class_allapps.js'; import { getTaskColumnPosFromHeaderRow } from '../util/lookups.js'; import { getTagsFromQseow } from '../util/tag.js'; import { getCustomPropertiesFromQseow } from '../util/customproperties.js'; +import { catchLog } from '../util/log.js'; const getHeaders = async (options) => { const records = []; @@ -421,7 +422,7 @@ const importTaskFromFile = async (options) => { } return false; } catch (err) { - logger.error(`IMPORT TASK 2: ${err.stack}`); + catchLog('IMPORT TASK 2', err); } }; diff --git a/src/lib/cmd/scramblefield.js b/src/lib/cmd/scramblefield.js index 19e3eb5..720c87d 100644 --- a/src/lib/cmd/scramblefield.js +++ b/src/lib/cmd/scramblefield.js @@ -1,6 +1,7 @@ import enigma from 'enigma.js'; import { setupEnigmaConnection, addTrafficLogging } from '../util/enigma.js'; import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; +import { catchLog } from '../util/log.js'; /** * @@ -28,7 +29,7 @@ const scrambleField = async (options) => { session = await enigma.create(configEnigma); logger.verbose(`Created session to server ${options.host}.`); } catch (err) { - logger.error(`Error creating session to server ${options.host}: ${err}`); + catchLog(`Error creating session to server ${options.host}`, err); process.exit(1); } @@ -39,7 +40,7 @@ const scrambleField = async (options) => { try { global = await session.open(); } catch (err) { - logger.error(`Error opening session to server ${options.host}: ${err}`); + catchLog(`Error opening session to server ${options.host}`, err); process.exit(1); } @@ -48,7 +49,7 @@ const scrambleField = async (options) => { engineVersion = await global.engineVersion(); logger.verbose(`Server ${options.host} has engine version ${engineVersion.qComponentVersion}.`); } catch (err) { - logger.error(`Error getting engine version from server ${options.host}: ${err}`); + catchLog(`Error getting engine version from server ${options.host}`, err); process.exit(1); } @@ -71,7 +72,7 @@ const scrambleField = async (options) => { const res = await app.scramble(field); logger.info(`Scrambled field "${field}"`); } catch (err) { - logger.error(`Failed scrambling field "${field}". Please make sure it exists in the app.`); + catchLog(`Error scrambling field "${field}". please make sure it exists in the app.`, err); } } @@ -86,7 +87,7 @@ const scrambleField = async (options) => { } } } catch (err) { - logger.error(err); + catchLog('Error in scrambleField', err); } }; diff --git a/src/lib/cmd/settaskcp.js b/src/lib/cmd/settaskcp.js index ab04cce..556b7be 100644 --- a/src/lib/cmd/settaskcp.js +++ b/src/lib/cmd/settaskcp.js @@ -1,6 +1,7 @@ import yesno from 'yesno'; import { logger } from '../../globals.js'; import { getCustomProperty, getTasksFromQseow, updateReloadTask } from '../task/task_qrs.js'; +import { catchLog } from '../util/log.js'; const updateTask = async (options, customPropertyDef, task) => new Promise(async (resolve, reject) => { @@ -213,7 +214,7 @@ const setTaskCustomProperty = async (options) => { return true; } } catch (err) { - logger.error(`SET RELOAD TASK CP: ${err}`); + catchLog(`SET RELOAD TASK CP`, err); return false; } }; diff --git a/src/lib/cmd/testconnection.js b/src/lib/cmd/testconnection.js index 0f489e4..2588787 100644 --- a/src/lib/cmd/testconnection.js +++ b/src/lib/cmd/testconnection.js @@ -1,5 +1,6 @@ import { logger, setLoggingLevel, isPkg, execPath } from '../../globals.js'; import getAboutFromQseow from '../util/about.js'; +import { catchLog } from '../util/log.js'; const testConnection = async (options) => { try { @@ -25,6 +26,7 @@ const testConnection = async (options) => { return aboutInfo; } catch (err) { + catchLog(`Error testing connection to Qlik Sense server ${options.host} on port ${options.port}`, err); logger.error(`EXPORT APP: ${err.stack}`); return false; } diff --git a/src/lib/cmd/useractivity.js b/src/lib/cmd/useractivity.js index 28df133..e0419c0 100644 --- a/src/lib/cmd/useractivity.js +++ b/src/lib/cmd/useractivity.js @@ -1,4 +1,5 @@ import { logger } from '../../globals.js'; +import { catchLog } from '../util/log.js'; export function getUserActivityProfessional(qrsInteractInstance) { // eslint-disable-next-line no-unused-vars, no-async-promise-executor @@ -7,7 +8,7 @@ export function getUserActivityProfessional(qrsInteractInstance) { try { result = await qrsInteractInstance.Get('license/professionalaccesstype/full'); } catch (err) { - logger.error(`USER ACTIVITY PROFESSIONAL: Error getting user activity info from QRS: ${err}`); + catchLog(`USER ACTIVITY PROFESSIONAL: Error getting user activity info from QRS`, err); } resolve(result.body); @@ -21,7 +22,7 @@ export function getUserActivityAnalyzer(qrsInteractInstance) { try { result = await qrsInteractInstance.Get('license/analyzeraccesstype/full'); } catch (err) { - logger.error(`USER ACTIVITY ANALYZER: Error getting user activity info from QRS: ${err}`); + catchLog(`USER ACTIVITY ANALYZER: Error getting user activity info from QRS`, err); } resolve(result.body); @@ -35,7 +36,7 @@ export getUserActivityAnalyzerTime(qrsInteractInstance) { try { result = await qrsInteractInstance.Get('license/analyzertimeaccesstype/full'); } catch (err) { - logger.error(`USER ACTIVITY ANALYZER TIME: Error getting user activity info from QRS: ${err}`); + catchLog(`USER ACTIVITY ANALYZER TIME: Error getting user activity info from QRS`, err); } resolve(result.body); @@ -49,7 +50,7 @@ export function getUserActivityLogin(qrsInteractInstance) { try { result = await qrsInteractInstance.Get('license/loginaccesstype/full'); } catch (err) { - logger.error(`USER ACTIVITY LOGIN: Error getting user activity info from QRS: ${err}`); + catchLog(`USER ACTIVITY LOGIN: Error getting user activity info from QRS`, err); } resolve(result.body); @@ -63,7 +64,7 @@ export function getUserActivityUser(qrsInteractInstance) { try { result = await qrsInteractInstance.Get('license/useraccesstype/full'); } catch (err) { - logger.error(`USER ACTIVITY USER: Error getting user activity info from QRS: ${err}`); + catchLog(`USER ACTIVITY USER: Error getting user activity info from QRS`, err); } resolve(result.body); diff --git a/src/lib/cmd/vistask.js b/src/lib/cmd/vistask.js index 319d566..fc33b05 100644 --- a/src/lib/cmd/vistask.js +++ b/src/lib/cmd/vistask.js @@ -5,7 +5,6 @@ import handlebars from 'handlebars'; import { Readable } from 'stream'; import { appVersion, logger, setLoggingLevel, isPkg, execPath, verifyFileExists } from '../../globals.js'; import QlikSenseTasks from '../task/class_alltasks.js'; -import { log } from 'console'; // js: 'application/javascript', const MIME_TYPES = { diff --git a/src/lib/task/class_allcompositeevents.js b/src/lib/task/class_allcompositeevents.js index 71da34f..f487176 100644 --- a/src/lib/task/class_allcompositeevents.js +++ b/src/lib/task/class_allcompositeevents.js @@ -3,6 +3,7 @@ import path from 'path'; import { logger, execPath, verifyFileExists } from '../../globals.js'; import setupQRSConnection from '../util/qrs.js'; import QlikSenseCompositeEvent from './class_compositeevent.js'; +import { catchLog } from '../util/log.js'; class QlikSenseCompositeEvents { // eslint-disable-next-line no-useless-constructor @@ -21,7 +22,7 @@ class QlikSenseCompositeEvents { this.fileCertKey = path.resolve(execPath, options.authCertKeyFile); } } catch (err) { - logger.error(`GET COMPOSITE EVENT: ${err}`); + catchLog(`GET COMPOSITE EVENT`, err); } } @@ -62,11 +63,11 @@ class QlikSenseCompositeEvents { resolve(this.taskList); }) .catch((err) => { - logger.error(`GET COMPOSITE EVENT 1: ${err}`); + catchLog(`GET COMPOSITE EVENT 1`, err); reject(err); }); } catch (err) { - logger.error(`GET COMPOSITE EVENT 2: ${err}`); + catchLog(`GET COMPOSITE EVENT 2`, err); reject(err); } }); diff --git a/src/lib/task/class_allschemaevents.js b/src/lib/task/class_allschemaevents.js index 376596c..c5556ce 100644 --- a/src/lib/task/class_allschemaevents.js +++ b/src/lib/task/class_allschemaevents.js @@ -3,6 +3,7 @@ import path from 'path'; import { logger, execPath } from '../../globals.js'; import setupQRSConnection from '../util/qrs.js'; import QlikSenseSchemaEvent from './class_schemaevent.js'; +import { catchLog } from '../util/log.js'; class QlikSenseSchemaEvents { // eslint-disable-next-line no-useless-constructor @@ -21,7 +22,7 @@ class QlikSenseSchemaEvents { this.fileCertKey = path.resolve(execPath, options.authCertKeyFile); } } catch (err) { - logger.error(`GET SCHEMA EVENT: ${err}`); + catchLog(`GET SCHEMA EVENT INIT`, err); } } @@ -45,7 +46,7 @@ class QlikSenseSchemaEvents { resolve(); } catch (err) { - logger.error(`GET SCHEMA EVENT 2: ${err}`); + catchLog(`GET SCHEMA EVENT 1`, err); reject(err); } }); @@ -79,11 +80,11 @@ class QlikSenseSchemaEvents { resolve(this.taskList); }) .catch((err) => { - logger.error(`GET SCHEMA EVENT 1: ${err}`); + catchLog(`GET SCHEMA EVENT 2`, err); reject(err); }); } catch (err) { - logger.error(`GET SCHEMA EVENT 2: ${err}`); + catchLog(`GET SCHEMA EVENT 3`, err); reject(err); } }); diff --git a/src/lib/task/class_alltasks.js b/src/lib/task/class_alltasks.js index 1dcda2a..49c4d62 100644 --- a/src/lib/task/class_alltasks.js +++ b/src/lib/task/class_alltasks.js @@ -20,6 +20,7 @@ import { getTagIdByName } from '../util/tag.js'; import { getCustomPropertyIdByName } from '../util/customproperties.js'; import { getAppById } from '../util/app.js'; import { taskExistById, getTaskById } from '../util/task.js'; +import { catchLog } from '../util/log.js'; class QlikSenseTasks { // eslint-disable-next-line no-useless-constructor @@ -53,7 +54,7 @@ class QlikSenseTasks { this.qlikSenseCompositeEvents = new QlikSenseCompositeEvents(); await this.qlikSenseCompositeEvents.init(options); } catch (err) { - logger.error(`QS TASK: ${err}`); + catchLog(`QS TASK`, err); } } @@ -1269,6 +1270,8 @@ class QlikSenseTasks { resolve(this.taskList); } catch (err) { + catchLog('PARSE TASKS FROM FILE 1', err); + if (err?.response?.status) { logger.error(`Received error ${err.response?.status}/${err.response?.statusText} from QRS API`); } @@ -1278,10 +1281,8 @@ class QlikSenseTasks { if (err?.config?.data) { logger.error(`Data sent to Sense: ${JSON.stringify(JSON.parse(err.config.data), null, 2)}}`); } - logger.error(`PARSE TASKS FROM FILE 1: ${err}`); reject(err); } - // return null; }); } @@ -1327,10 +1328,10 @@ class QlikSenseTasks { } }) .catch((err) => { - logger.error(`CREATE COMPOSITE EVENT IN QSEOW 1: ${err}`); + catchLog('CREATE COMPOSITE EVENT IN QSEOW 1', err); }); } catch (err) { - logger.error(`CREATE COMPOSITE EVENT IN QSEOW 2: ${err}`); + catchLog('CREATE COMPOSITE EVENT IN QSEOW 2', err); reject(err); } }); @@ -1388,11 +1389,11 @@ class QlikSenseTasks { } }) .catch((err) => { - logger.error(`CREATE RELOAD TASK IN QSEOW 1: ${err}`); + catchLog('CREATE RELOAD TASK IN QSEOW 1', err); reject(err); }); } catch (err) { - logger.error(`CREATE RELOAD TASK IN QSEOW 2: ${err}`); + catchLog('CREATE RELOAD TASK IN QSEOW 2', err); reject(err); } }); @@ -1450,11 +1451,11 @@ class QlikSenseTasks { } }) .catch((err) => { - logger.error(`CREATE EXTERNAL PROGRAM TASK IN QSEOW 1: ${err}`); + catchLog('CREATE EXTERNAL PROGRAM TASK IN QSEOW 1', err); reject(err); }); } catch (err) { - logger.error(`CREATE EXTERNAL PROGRAM TASK IN QSEOW 2: ${err}`); + catchLog('CREATE EXTERNAL PROGRAM TASK IN QSEOW 2', err); reject(err); } }); @@ -1512,7 +1513,7 @@ class QlikSenseTasks { } }); } catch (err) { - logger.error(`SAVE TASK TO QSEOW 1: ${err}`); + catchLog('SAVE TASK TO QSEOW 1', err); reject2(); } }); @@ -1520,7 +1521,7 @@ class QlikSenseTasks { } resolve(); } catch (err) { - logger.error(`SAVE TASK TO QSEOW 2: ${err}`); + catchLog('SAVE TASK TO QSEOW 2', err); reject(err); } }); @@ -1857,7 +1858,7 @@ class QlikSenseTasks { return subTree; // console.log('subTree: ' + JSON.stringify(subTree)); } catch (err) { - logger.error(`GET TASK SUBTREE (tree): ${err.stack}`); + catchLog('GET TASK SUBTREE (tree)', err); return false; } } @@ -1931,7 +1932,7 @@ class QlikSenseTasks { return subTree; } catch (err) { - logger.error(`GET TASK SUBTREE (table): ${err}`); + catchLog('GET TASK SUBTABLE (table)', err); return null; } } @@ -1947,7 +1948,7 @@ class QlikSenseTasks { resolve(tableTaskBasic); } } catch (err) { - logger.error(`GET TASK TABLE: ${err}`); + catchLog('GET TASK TABLE', err); reject(); } }); @@ -1961,7 +1962,7 @@ class QlikSenseTasks { logger.verbose(`Getting tasks from QSEoW...`); await this.getTasksFromQseow(); } catch (err) { - logger.error(`GET TASK MODEL FROM QSEOW 1: ${err}`); + catchLog('GET TASK MODEL FROM QSEOW 1', err); return false; } @@ -1972,7 +1973,7 @@ class QlikSenseTasks { logger.silly(`Schema events from QSEoW: ${JSON.stringify(result1, null, 2)}`); } catch (err) { - logger.error(`GET TASK MODEL FROM QSEOW 2: ${err}`); + catchLog('GET TASK MODEL FROM QSEOW 2', err); return false; } @@ -1983,7 +1984,7 @@ class QlikSenseTasks { logger.silly(`Composite events from QSEoW: ${JSON.stringify(result2, null, 2)}`); } catch (err) { - logger.error(`GET TASK MODEL FROM QSEOW 3: ${err}`); + catchLog('GET TASK MODEL FROM QSEOW 3', err); return false; } diff --git a/src/lib/task/class_task.js b/src/lib/task/class_task.js index 17548c7..a51bdfe 100644 --- a/src/lib/task/class_task.js +++ b/src/lib/task/class_task.js @@ -1,11 +1,7 @@ import { Duration } from 'luxon'; - // const { randomWords } = require('random-words'); - import { logger } from '../../globals.js'; - import { mapTaskExecutionStatus } from '../util/lookups.js'; - // const randomWords2 = (...args) => import('random-words').then(({ default: randomWords }) => randomWords(...args)); class QlikSenseTask { diff --git a/src/lib/task/task_qrs.js b/src/lib/task/task_qrs.js index 12909e7..b339aee 100644 --- a/src/lib/task/task_qrs.js +++ b/src/lib/task/task_qrs.js @@ -1,6 +1,5 @@ import axios from 'axios'; import path from 'path'; - // const { promises: Fs } = require('fs'); // const yesno = require('yesno'); @@ -8,6 +7,7 @@ import { logger, execPath } from '../../globals.js'; import setupQRSConnection from '../util/qrs.js'; import getCertFilePaths from '../util/cert.js'; +import { catchLog } from '../util/log.js'; // const { QlikSenseTasks } = require('./class_alltasks'); // const { mapEventType, mapIncrementOption, mapDaylightSavingTime, mapRuleState } = require('../util/lookups'); @@ -56,7 +56,7 @@ export const getCustomProperty = async (options) => { cp = false; } } catch (err) { - logger.error(`GET CP FROM QRS: ${err.stack}`); + catchLog(`GET CP FROM QRS`, err); } return cp; }; @@ -129,7 +129,7 @@ export const getTasksFromQseow = async (options) => { logger.debug(`GET TASK 3: List of tasks: ${JSON.stringify(taskList)}`); return taskList; } catch (err) { - logger.error(`GET TASKS FROM QRS: ${err.stack}`); + catchLog(`GET TASKS FROM QRS`, err); return false; } }; @@ -151,7 +151,7 @@ export const updateReloadTask = async (options, payload) => { const result = await axios.request(axiosConfig); logger.debug(`UPDATE RELOAD TASK CUSTOM PROPERTY: Result=${result.status}`); } catch (err) { - logger.error(`UPDATE RELOAD TASK: ${err.stack}`); + catchLog(`UPDATE RELOAD TASK`, err); return false; } return true; diff --git a/src/lib/util/about.js b/src/lib/util/about.js index b6ea131..9833d89 100644 --- a/src/lib/util/about.js +++ b/src/lib/util/about.js @@ -2,6 +2,7 @@ import axios from 'axios'; import path from 'path'; import { logger, execPath } from '../../globals.js'; import setupQRSConnection from './qrs.js'; +import { catchLog } from './log.js'; function getAboutFromQseow(options) { return new Promise((resolve, reject) => { @@ -41,7 +42,7 @@ function getAboutFromQseow(options) { resolve(false); }) .catch((err) => { - logger.error(`GET ABOUT INFO: ${err}`); + catchLog('GET ABOUT INFO', err); }); }); } diff --git a/src/lib/util/app.js b/src/lib/util/app.js index eda7cbf..fc8631f 100644 --- a/src/lib/util/app.js +++ b/src/lib/util/app.js @@ -3,6 +3,7 @@ import path from 'path'; import { validate } from 'uuid'; import { logger, execPath, getCliOptions } from '../../globals.js'; import setupQRSConnection from './qrs.js'; +import { catchLog } from './log.js'; export async function getApps(options, idArray, tagArray) { try { @@ -91,7 +92,7 @@ export async function getApps(options, idArray, tagArray) { return apps; } catch (err) { - logger.error(err.stack); + catchLog('GET APPS', err); return false; } } @@ -154,13 +155,7 @@ export async function getAppById(appId, optionsParam) { return false; } catch (err) { - logger.error(`GET APP BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`GET APP BY ID:\n ${err.stack}`); - } - + catchLog('GET APP BY ID', err); return false; } } @@ -209,13 +204,7 @@ export async function deleteAppById(appId, options) { return true; } catch (err) { - logger.error(`DELETE APP: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`DELETE APP:\n ${err.stack}`); - } - + catchLog('DELETE APP', err); return false; } } @@ -278,13 +267,7 @@ export async function appExistById(appId, options) { return false; } catch (err) { - logger.error(`APP EXIST BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`APP EXIST BY ID:\n ${err.stack}`); - } - + catchLog('APP EXIST BY ID', err); return false; } } diff --git a/src/lib/util/assert-options.js b/src/lib/util/assert-options.js index bcae94e..b8c0dbb 100644 --- a/src/lib/util/assert-options.js +++ b/src/lib/util/assert-options.js @@ -4,7 +4,7 @@ import { validate as uuidValidate } from 'uuid'; import fs from 'fs'; import { logger, execPath, mergeDirFilePath, verifyFileExists } from '../../globals.js'; -const sharedParamAssertOptions = async (options) => { +export const sharedParamAssertOptions = async (options) => { // Ensure that parameters common to all commands are valid if (options.authType === undefined || !options.authType) { logger.error('Mandatory option --auth-type is missing. Use it to specify how authorization with Qlik Sense will be done.'); @@ -47,7 +47,7 @@ const sharedParamAssertOptions = async (options) => { } }; -const userActivityCustomPropertyAssertOptions = (options) => { +export const userActivityCustomPropertyAssertOptions = (options) => { const newOptions = options; // If certificate authentication is used: certs and user dir/id must be present. @@ -65,7 +65,7 @@ const userActivityCustomPropertyAssertOptions = (options) => { return newOptions; }; -const masterItemImportAssertOptions = (options) => { +export const masterItemImportAssertOptions = (options) => { if (options.colRefBy === undefined || !options.colRefBy) { logger.error( 'Mandatory option --col-ref-by is missing. Use it to specify how Excel file columns are referenced (by name or position)' @@ -74,7 +74,7 @@ const masterItemImportAssertOptions = (options) => { } }; -const masterItemMeasureDeleteAssertOptions = (options) => { +export const masterItemMeasureDeleteAssertOptions = (options) => { // Make sure options are valid for deleting master measures // Either --delete-all OR (--id-type and --master-item) should be specified @@ -100,7 +100,7 @@ const masterItemMeasureDeleteAssertOptions = (options) => { } }; -const masterItemDimDeleteAssertOptions = (options) => { +export const masterItemDimDeleteAssertOptions = (options) => { // Make sure options are valid for deleting master dimensions // Either --delete-all OR (--id-type and --master-item) should be specified @@ -127,22 +127,22 @@ const masterItemDimDeleteAssertOptions = (options) => { }; // eslint-disable-next-line no-unused-vars -const masterItemGetAssertOptions = (options) => { +export const masterItemGetAssertOptions = (options) => { // }; // eslint-disable-next-line no-unused-vars -const getScriptAssertOptions = (options) => { +export const getScriptAssertOptions = (options) => { // }; // eslint-disable-next-line no-unused-vars -const getBookmarkAssertOptions = (options) => { +export const getBookmarkAssertOptions = (options) => { // }; // eslint-disable-next-line no-unused-vars -const getTaskAssertOptions = (options) => { +export const getTaskAssertOptions = (options) => { // ---task-id and --task-tag only allowed for task tables, not trees if (options.taskId || options.taskTag) { if (options.outputFormat === 'tree') { @@ -204,12 +204,12 @@ const getTaskAssertOptions = (options) => { }; // eslint-disable-next-line no-unused-vars -const setTaskCustomPropertyAssertOptions = (options) => { +export const setTaskCustomPropertyAssertOptions = (options) => { // }; // eslint-disable-next-line no-unused-vars -const taskImportAssertOptions = (options) => { +export const taskImportAssertOptions = (options) => { // If --import-app is specified, the import file type must be Excel if (options.importApp && options.fileType !== 'excel') { logger.error( @@ -234,17 +234,17 @@ const taskImportAssertOptions = (options) => { }; // eslint-disable-next-line no-unused-vars -const appImportAssertOptions = (options) => { +export const appImportAssertOptions = (options) => { // }; // Assert that values in Excel sheet are valid -const appImportAssertExcelSheet = (options) => { +export const appImportAssertExcelSheet = (options) => { // }; // eslint-disable-next-line no-unused-vars -const appExportAssertOptions = async (options) => { +export const appExportAssertOptions = async (options) => { // Verify output directory exists // const outputDir = mergeDirFilePath([options.outputDir]); // const existsOutputDir = await fs.promises.access(outputDir); @@ -254,7 +254,7 @@ const appExportAssertOptions = async (options) => { // } }; -const variableGetAssertOptions = (options) => { +export const variableGetAssertOptions = (options) => { // Make sure options are valid for getting variables // At least one app specified? if (options.appId === undefined && options.appTag === undefined) { @@ -263,7 +263,7 @@ const variableGetAssertOptions = (options) => { } }; -const variableDeleteAssertOptions = (options) => { +export const variableDeleteAssertOptions = (options) => { // Make sure options are valid for deleting variables // At least one app specified? @@ -294,22 +294,3 @@ const variableDeleteAssertOptions = (options) => { process.exit(1); } }; - -export default { - sharedParamAssertOptions, - userActivityCustomPropertyAssertOptions, - masterItemImportAssertOptions, - masterItemMeasureDeleteAssertOptions, - masterItemDimDeleteAssertOptions, - masterItemGetAssertOptions, - variableGetAssertOptions, - variableDeleteAssertOptions, - getScriptAssertOptions, - getBookmarkAssertOptions, - getTaskAssertOptions, - setTaskCustomPropertyAssertOptions, - taskImportAssertOptions, - appImportAssertOptions, - appImportAssertExcelSheet, - appExportAssertOptions, -}; diff --git a/src/lib/util/cert.js b/src/lib/util/cert.js index f607621..b084deb 100644 --- a/src/lib/util/cert.js +++ b/src/lib/util/cert.js @@ -1,5 +1,6 @@ import path from 'path'; import { logger, execPath } from '../../globals.js'; +import { catchLog } from './log.js'; const getCertFilePaths = async (options) => { let fileCert; @@ -9,7 +10,7 @@ const getCertFilePaths = async (options) => { fileCert = path.resolve(execPath, options.authCertFile); fileCertKey = path.resolve(execPath, options.authCertKeyFile); } catch (err) { - logger.error(`GET TASK QRS (ID): ${err.stack}. Exiting.`); + catchLog('GET TASK QRS (ID). Exiting. ', err); process.exit(1); } return { fileCert, fileCertKey }; diff --git a/src/lib/util/enigma.js b/src/lib/util/enigma.js index e17a63b..b11ebb3 100644 --- a/src/lib/util/enigma.js +++ b/src/lib/util/enigma.js @@ -1,4 +1,4 @@ -import SenseUtilities from 'enigma.js/sense-utilities'; +import SenseUtilities from 'enigma.js/sense-utilities.js'; import WebSocket from 'ws'; import path from 'path'; import { readFileSync } from 'fs'; diff --git a/src/lib/util/log.js b/src/lib/util/log.js index ff2f0e1..2ee402a 100644 --- a/src/lib/util/log.js +++ b/src/lib/util/log.js @@ -1,6 +1,6 @@ import { logger, appVersion, isPkg, execPath } from '../../globals.js'; -const logStartupInfo = (options, cmd, cmdDesc) => { +export const logStartupInfo = (options, cmd, cmdDesc) => { logger.info('-----------------------------------------------------------'); logger.info('| Ctrl-Q'); logger.info('| '); @@ -21,4 +21,20 @@ const logStartupInfo = (options, cmd, cmdDesc) => { logger.verbose(``); }; -export default logStartupInfo; +// Function used to provide consistent logging to all try-catch blocks +export const catchLog = (msgContext, err) => { + if (isPkg) { + if (err.message) { + logger.error(`${msgContext}: ${err.message}`); + } else { + logger.error(`${msgContext}: ${err}`); + } + } else if (err.stack) { + logger.error(`${msgContext}: ${err.stack}`); + } else if (err.message) { + logger.error(`${msgContext}: ${err.message}`); + } else { + logger.error(`${msgContext}: ${err}`); + } +} + diff --git a/src/lib/util/tag.js b/src/lib/util/tag.js index 07dca3e..3ff7edd 100644 --- a/src/lib/util/tag.js +++ b/src/lib/util/tag.js @@ -2,6 +2,7 @@ import axios from 'axios'; import path from 'path'; import { logger, execPath } from '../../globals.js'; import setupQRSConnection from './qrs.js'; +import { catchLog } from './log.js'; export function getTagsFromQseow(options) { return new Promise((resolve, _reject) => { @@ -41,7 +42,7 @@ export function getTagsFromQseow(options) { resolve(false); }) .catch((err) => { - logger.error(`GET TAGS FROM QSEoW: ${err}`); + catchLog('GET TAGS FROM QSEoW', err); }); }); } diff --git a/src/lib/util/task.js b/src/lib/util/task.js index dce4aa6..9b31d1b 100644 --- a/src/lib/util/task.js +++ b/src/lib/util/task.js @@ -4,6 +4,7 @@ import path from 'path'; import { validate } from 'uuid'; import { logger, execPath, getCliOptions } from '../../globals.js'; import setupQRSConnection from './qrs.js'; +import { catchLog } from './log.js'; // Check if a task with a given id exists // Look for all kinds of tasks, not just reload tasks @@ -74,13 +75,7 @@ export async function taskExistById(taskId, optionsParam) { return false; } catch (err) { - logger.error(`TASK EXIST BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`TASK EXIST BY ID:\n ${err.stack}`); - } - + catchLog('TASK EXIST BY ID', err); return false; } } @@ -143,13 +138,7 @@ export async function getTaskByName(taskName, optionsParam) { } return false; } catch (err) { - logger.error(`GET TASK BY NAME: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`GET TASK BY NAME:\n ${err.stack}`); - } - + catchLog('GET TASK BY NAME', err); return false; } } @@ -221,13 +210,7 @@ export async function getTaskById(taskId, optionsParam) { return false; } catch (err) { - logger.error(`GET TASK BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`GET TASK BY ID:\n ${err.stack}`); - } - + catchLog('GET TASK BY ID', err); return false; } } @@ -297,13 +280,7 @@ export async function deleteReloadTaskById(taskId, optionsParam) { return false; } catch (err) { - logger.error(`DELETE RELOAD TASK BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`DELETE RELOAD TASK BY ID:\n ${err.stack}`); - } - + catchLog('DELETE RELOAD TASK BY ID', err); return false; } } @@ -373,13 +350,7 @@ export async function deleteExternalProgramTaskById(taskId, optionsParam) { return false; } catch (err) { - logger.error(`DELETE EXT PGM TASK BY ID: ${err}`); - - // Show stack trace if available - if (err?.stack) { - logger.error(`DELETE EXT PGM TASK BY ID:\n ${err.stack}`); - } - + catchLog('DELETE EXT PGM TASK BY ID', err); return false; } }