From b6c1a986f9ee6f7cb4f132b552b5c9df02a96376 Mon Sep 17 00:00:00 2001 From: Cihad Tekin Date: Fri, 27 Dec 2024 14:05:45 +0300 Subject: [PATCH] [system-utility] NamespaceNotFound is thrown when profiler gets run for the first time --- plugins/system-utility/api/system.utility.js | 24 ++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/system-utility/api/system.utility.js b/plugins/system-utility/api/system.utility.js index 44e0f298932..da6902503f4 100644 --- a/plugins/system-utility/api/system.utility.js +++ b/plugins/system-utility/api/system.utility.js @@ -471,13 +471,23 @@ async function stopProfiler(processName) { const errors = []; // clear old files - await new Promise( - (res, rej) => countlyFs.gridfs.deleteAll( - PROFILER_DIR, - null, - err => err ? rej(err) : res() - ) - ); + try { + await new Promise( + (res, rej) => countlyFs.gridfs.deleteAll( + PROFILER_DIR, + null, + err => err ? rej(err) : res() + ) + ); + } + catch (err) { + if (err.code === 26) { // NamespaceNotFound: thrown when there's no collection initially + // do nothing... + } + else { + throw err; + } + } // coverage try {