From da58b9c573b3992841169d32b453e79c9d7b16c4 Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Mon, 25 Aug 2025 10:55:20 +0200 Subject: [PATCH] Error logging with stack trace --- hosts.js | 29 ++++++++++++++++++++--------- tokens.js | 34 ++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/hosts.js b/hosts.js index 36d4307..8423f3e 100644 --- a/hosts.js +++ b/hosts.js @@ -42,12 +42,14 @@ async function isConnected(hostID) { ); Log(`[${shared.now()}] ${hostID} connected: ${response.data.connected}`); return response.data.connected; - } - catch (error) { + } catch (error) { + Log( + `[${shared.now()}] Errore nella verifica dello stato per l'host ${hostID}` + ); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nella verifica dello stato per l'host ${hostID}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); - } + } } async function initHostList() { @@ -78,8 +80,10 @@ async function initHostList() { }); } catch (error) { Log( - `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}` + `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.` ); + Log(`[${shared.now()}] ${error}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -97,8 +101,10 @@ async function initHostList() { hostIDs.push(response.data[0].id); } catch (error) { Log( - `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}` + `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.` ); + Log(`[${shared.now()}] ${error}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -124,8 +130,10 @@ async function initHostList() { hostIDs.push(response.data.id); } catch (error) { Log( - `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}` + `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.` ); + Log(`[${shared.now()}] ${error}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -143,8 +151,10 @@ async function initHostList() { hostIDs.push(response.data.id); } catch (error) { Log( - `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host: ${error}` + `[${shared.now()}] Errore nella verifica e aggiunta al monitoraggio di un host.` ); + Log(`[${shared.now()}] ${error}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -164,8 +174,9 @@ async function initHostList() { hostIDs.push(element.id); }); } catch (error) { + Log(`[${shared.now()}] Errore nel tentativo di reperire tutti i peer.`); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nel tentativo di reperire tutti i peer`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } diff --git a/tokens.js b/tokens.js index 8550a4b..a5c9f71 100644 --- a/tokens.js +++ b/tokens.js @@ -7,19 +7,19 @@ let userID; async function TokenRenew() { setInterval(async () => { shared.eventEmitter.emit("tokenRenewalStart"); - // ottieni l'ID dell'utente associato al token - userID = await getUserID(); + // ottieni l'ID dell'utente associato al token + userID = await getUserID(); - // ottieni l'ID del token corrente - const tokenID = await getCurrentTokenID(); + // ottieni l'ID del token corrente + const tokenID = await getCurrentTokenID(); - // crea nuovo token - const newToken = await getNewToken(); - shared.setToken(newToken); + // crea nuovo token + const newToken = await getNewToken(); + shared.setToken(newToken); - // cancella il token precedente - await deleteToken(tokenID); - shared.eventEmitter.emit("tokenRenewalEnd"); + // cancella il token precedente + await deleteToken(tokenID); + shared.eventEmitter.emit("tokenRenewalEnd"); }, day - hour); } @@ -37,8 +37,9 @@ async function getUserID() { Log(`[${shared.now()}] UserID: ${response.data.id}`); return response.data.id; } catch (error) { + Log(`[${shared.now()}] Errore nel reperire l'ID dell'utente corrente.`); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nel reperire l'ID dell'utente corrente`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -55,8 +56,11 @@ async function deleteToken(tokenID) { ); Log(`[${shared.now()}] Token con ID ${tokenID} cancellato con successo`); } catch (error) { + Log( + `[${shared.now()}] Errore nella cancellazione del token con ID ${tokenID}.` + ); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nella cancellazione del token con ID ${tokenID}`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -79,8 +83,9 @@ async function getCurrentTokenID() { Log(`[${shared.now()}] CurrentTokenID: ${token.id}`); return token.id; } catch (error) { + Log(`[${shared.now()}] Errore nel reperire il token corrente.`); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nel reperire il token corrente`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } } @@ -104,8 +109,9 @@ async function getNewToken() { Log(`[${shared.now()}] Nuovo token creato: ${response.data.plain_token}`); return response.data.plain_token; } catch (error) { + Log(`[${shared.now()}] Errore nella creazione di un nuovo token.`); Log(`[${shared.now()}] ${error}`); - Log(`[${shared.now()}] Errore nella creazione di un nuovo token`); + Log(`[${shared.now()}] Debug: ${error.stack}`); process.exit(3); } }