From 0ef1dcd891b72a1d91fd50429782ef224912696f Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Wed, 30 May 2018 09:29:14 +0200 Subject: [PATCH] Logs and Error Handling improvements --- CloudVM/CloudRequire.js | 6 +-- CloudVM/CloudVM.js | 77 +++++++++++++++++++++++----------- CloudVM/PoloniexAPIClient.js | 4 +- Exchanges/PoloniexAPIClient.js | 4 +- Scripts/AppLoader.js | 2 +- 5 files changed, 61 insertions(+), 32 deletions(-) diff --git a/CloudVM/CloudRequire.js b/CloudVM/CloudRequire.js index 110911036..566965ff7 100644 --- a/CloudVM/CloudRequire.js +++ b/CloudVM/CloudRequire.js @@ -1,6 +1,6 @@ function newCloudRequire(BOT, DEBUG_MODULE) { - const FULL_LOG = true; + const INFO_LOG = true; const LOG_FILE_CONTENT = false; const MODULE_NAME = "Cloud Require"; @@ -23,7 +23,7 @@ try { - if (FULL_LOG === true) { logger.write("[INFO] downloadBot -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] downloadBot -> Entering function."); } let filePath = "Bots" + "/" + bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name + "/" + "User.Bot.js"; @@ -46,7 +46,7 @@ try { - if (FULL_LOG === true) { logger.write("[INFO] downloadCommons -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] downloadCommons -> Entering function."); } let filePath = "Bots" + "/" + bot.devTeam + "/" + bot.repo + "/" + "Commons.js"; diff --git a/CloudVM/CloudVM.js b/CloudVM/CloudVM.js index 6b7957952..c0f72fb83 100644 --- a/CloudVM/CloudVM.js +++ b/CloudVM/CloudVM.js @@ -20,60 +20,89 @@ function newCloudVM() { function onBotPlayPressed(pUI_COMMANDS) { - window.SHALL_BOT_STOP = false; + try { - window.CURRENT_ENVIRONMENT = "Develop"; - window.STORAGE_PERMISSIONS = ecosystem.getStoragePermissions(); - window.EXCHANGE_KEYS = ecosystem.getExchangeKeys(); - window.USER_LOGGED_IN = window.localStorage.getItem("userName"); - window.USER_DEV_TEAM = window.localStorage.getItem("devTeam"); + if (INFO_LOG === true) { logger.write("[INFO] onBotPlayPressed -> Entering function."); } - root.initialize(pUI_COMMANDS, onInitialized); + window.SHALL_BOT_STOP = false; - function onInitialized() { + window.CURRENT_ENVIRONMENT = "Develop"; + window.STORAGE_PERMISSIONS = ecosystem.getStoragePermissions(); + window.EXCHANGE_KEYS = ecosystem.getExchangeKeys(); + window.USER_LOGGED_IN = window.localStorage.getItem("userName"); + window.USER_DEV_TEAM = window.localStorage.getItem("devTeam"); - root.start(); + root.initialize(pUI_COMMANDS, onInitialized); - intervalHandler = setInterval(checkForChangesInBotCode, 10000); + function onInitialized() { + try { + + if (INFO_LOG === true) { logger.write("[INFO] onBotPlayPressed -> Entering function."); } + + root.start(); + + intervalHandler = setInterval(checkForChangesInBotCode, 10000); + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onBotPlayPressed -> onInitialized -> err.message = " + err.message); } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] onBotPlayPressed -> err.message = " + err.message); } } - } function onBotStopPressed() { + if (INFO_LOG === true) { logger.write("[INFO] onBotStopPressed -> Entering function."); } + window.SHALL_BOT_STOP = true; } function checkForChangesInBotCode() { - let botFunction = newUserBot; + try { - if (botFunction !== undefined) { + if (INFO_LOG === true) { logger.write("[INFO] checkForChangesInBotCode -> Entering function."); } - let currentBotCode = botFunction.toString(); + let botFunction = newUserBot; - if (previousBotCode !== "") { + if (botFunction !== undefined) { - if (currentBotCode !== previousBotCode) { + let currentBotCode = botFunction.toString(); - console.log("Bot code changes detected."); + if (previousBotCode !== "") { - let path = "AABrowserAPI" + "/" - + "saveBotCode" - ; + if (currentBotCode !== previousBotCode) { - callServer(currentBotCode, path, onServerResponse); + console.log("Bot code changes detected."); - function onServerResponse(err) { + let path = "AABrowserAPI" + "/" + + "saveBotCode" + ; - console.log("Server responded: " + err); + callServer(currentBotCode, path, onServerResponse); + + function onServerResponse(err) { + + if (INFO_LOG === true) { logger.write("[INFO] checkForChangesInBotCode -> onServerResponse -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] checkForChangesInBotCode -> onServerResponse -> err = " + err); } + + } } } + + previousBotCode = currentBotCode; } - previousBotCode = currentBotCode; + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] checkForChangesInBotCode -> err.message = " + err.message); } } } } \ No newline at end of file diff --git a/CloudVM/PoloniexAPIClient.js b/CloudVM/PoloniexAPIClient.js index c144e4384..4fa2608ca 100644 --- a/CloudVM/PoloniexAPIClient.js +++ b/CloudVM/PoloniexAPIClient.js @@ -1,6 +1,6 @@ function newPoloniexAPIClient(pKey, pSecret) { - const FULL_LOG = true; + const INFO_LOG = true; const LOG_FILE_CONTENT = false; let key = pKey; @@ -29,7 +29,7 @@ let stringExchangeResponse = JSON.stringify(exchangeResponse); let stringExchangeErr = JSON.stringify(exchangeErr); - if (FULL_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); } + if (INFO_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); } if (LOG_FILE_CONTENT === true) { logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); } if (stringExchangeErr.indexOf("ETIMEDOUT") > 0 || diff --git a/Exchanges/PoloniexAPIClient.js b/Exchanges/PoloniexAPIClient.js index 6439d7ab7..18a5484e3 100644 --- a/Exchanges/PoloniexAPIClient.js +++ b/Exchanges/PoloniexAPIClient.js @@ -401,7 +401,7 @@ analizeResponse: function (logger, exchangeErr, exchangeResponse, notOkCallBack, okCallBack) { - const FULL_LOG = false; + const INFO_LOG = false; const LOG_FILE_CONTENT = false; /* This function analizes the different situations we might encounter trying to access Poloniex and returns appropiate standard errors. */ @@ -411,7 +411,7 @@ let stringExchangeResponse = JSON.stringify(exchangeResponse); let stringExchangeErr = JSON.stringify(exchangeErr); - if (FULL_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); } + if (INFO_LOG === true) { logger.write("[INFO] analizeResponse -> exchangeErr = " + stringExchangeErr); } if (LOG_FILE_CONTENT === true) { logger.write("[INFO] analizeResponse -> exchangeResponse = " + stringExchangeResponse); } if (stringExchangeErr.indexOf("ETIMEDOUT") > 0 || diff --git a/Scripts/AppLoader.js b/Scripts/AppLoader.js index 8c904a74a..c640b2472 100644 --- a/Scripts/AppLoader.js +++ b/Scripts/AppLoader.js @@ -1,6 +1,6 @@ function newAppLoader() { - const FULL_LOG = false; + const INFO_LOG = false; const LOG_FILE_CONTENT = false; const MODULE_NAME = "App Loader";