From 4cc8569dd0f32b8f4b2b3c27942021e58a2454fa Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 30 Apr 2018 12:29:40 +0200 Subject: [PATCH] Error Handling at FileSequence --- .vs/AAWeb/v15/.suo | Bin 67584 -> 67584 bytes Files/DailyFiles.js | 1 + Files/FileCursor.js | 1 + Files/FileSequence.js | 162 ++++++++++++++++++++++++------------------ server.js | 2 +- 5 files changed, 96 insertions(+), 70 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index 0540a584a777a92ca63a48bf5a319675bfc4b252..ecb8b28dc0adc46e55ff124c1e0d0a4d71bf6d5a 100644 GIT binary patch delta 848 zcmb7C-Ahwp7(egXIdh*fk-l`wHj!3CT9#Nw=8~=wYZVgo;R+OlCP@(ri=K~Mz zT@vLl@ushS-Xnfz%mcr4lr`eDRIYCl1R+OpFyt*oR+6^4sZjU3c$m(g^s|}HdTy56 zne6KppOcLC1k*DumA4a6;&x)SsD)YK(N&puP^p68BAC&mt17WjR!e9gsDx@hri&Q# z%uKn7pbGG-r3+=437q4xfR8C|!^Ejsrc*~#_0$eo6%6uk2X2Tg$om?PF-cP(uO70R zxTPV>lvb_MB8Im*xTCF2r}mv6s8DW+N`Mo#yGA`()*|0n4xY5T6K9ZzqzeI{0H}lxrfqi7k97W@oUyFd)jE z>>hF3v1|APR%(jbACFo-t@LixK9%Ue>PLTJCCju;lfxAcRl^gHasJz8AaHKT45VEz?aZrDdyyXsa_52BlUkf zX%I@3Vd{ZNmgy=b#1?$8OdD{yzYgza-e z-&dkC(`-9guo4_oVaf*x>PD%Hp#~48uQNn5Kk{Vc=5orsh~0NL(d!%6Bs%h)^j%*9 O@foYS9z2=x?*9e(h%wRt delta 864 zcmbVITS!zv7~YvZXWiS0U4$?%p@_A*Xscv})OyVb&Dd^G54uGwC0a_73ZdtaAOxZ9 zhp=WvJGe$+Hz%@;@{+6((nh`X+H+Ap_!3>`sJjF`6b*dLKmRxLec$}*fTRvc_nN8P zDla~5=56#VA!TThYRC>emeMR$P-W7$4>MvL(=e+}N;XpB2~`5fz{wvI%Oeq==&mNoSUf8-f}KkDF)kc(K32RaK*w6`?7 zp=nvc2Ufm?g@`pp{6?Q+)rydC=Vg<#1n+MiL*8vSzc_j(2~L&kARCQy;aN3CL%#NA6DN3CP6JJf(GjS^Zsh7{5ID6xa z*e3;c!#B}Ht53q$u?hXRa)j=r@joPj(Qg=zS-3o3Px4OxX3{6>8UcMo#za3}ac!Z8 j@bD`mfjs}6El?a)*CX>qW#->BkQH-7iGJq8vB0)p_QfAU diff --git a/Files/DailyFiles.js b/Files/DailyFiles.js index 7506dc06d..fc876255c 100644 --- a/Files/DailyFiles.js +++ b/Files/DailyFiles.js @@ -3,6 +3,7 @@ function newDailyFiles() { const MODULE_NAME = "Daily Files"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; diff --git a/Files/FileCursor.js b/Files/FileCursor.js index 8d64789ee..daf8420be 100644 --- a/Files/FileCursor.js +++ b/Files/FileCursor.js @@ -3,6 +3,7 @@ function newFileCursor() { const MODULE_NAME = "File Cursor"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; diff --git a/Files/FileSequence.js b/Files/FileSequence.js index ffa28cb6c..6f485fd95 100644 --- a/Files/FileSequence.js +++ b/Files/FileSequence.js @@ -3,6 +3,7 @@ function newFileSequence() { const MODULE_NAME = "File Sequence"; const INFO_LOG = false; + const ERROR_LOG = true; const logger = newDebugLog(); logger.fileName = MODULE_NAME; @@ -25,97 +26,60 @@ function newFileSequence() { function initialize(pDevTeam, pBot, pProduct, pSet, pExchange, pMarket, callBackFunction) { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } + try { - let exchange = ecosystem.getExchange(pProduct, pExchange); + if (INFO_LOG === true) { logger.write("[INFO] initialize -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } - if (exchange === undefined) { + let exchange = ecosystem.getExchange(pProduct, pExchange); - throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; + if (exchange === undefined) { - } + throw "Exchange not supoorted by this pProduct of the ecosystem! - pDevTeam.codeName = " + pDevTeam.codeName + ", pBot.codeName = " + pBot.codeName + ", pProduct.codeName = " + pProduct.codeName + ", pExchange = " + pExchange; - fileCloud = newFileCloud(); - fileCloud.initialize(pBot); - - /* First we will get the sequence max number */ - - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, "Sequence", onSequenceFileReceived); - - function onSequenceFileReceived(err, file) { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Entering function."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } - - switch (err.result) { - case GLOBAL.DEFAULT_OK_RESPONSE.result: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received OK Response."); } - break; - } - - case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response."); } - callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); - return; - } - - case GLOBAL.CUSTOM_OK_RESPONSE.result: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } - - callBackFunction(err); - return; - } - - case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } - - callBackFunction(err); - return; - } - - default: { - - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response."); } - callBackFunction(err); - return; - } } - maxSequence = Number(file); + fileCloud = newFileCloud(); + fileCloud.initialize(pBot); - /* Now we will get the sequence of files */ + /* First we will get the sequence max number */ - for (let i = 0; i <= maxSequence; i++) { + fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, "Sequence", onSequenceFileReceived); - fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, i, onFileReceived); + function onSequenceFileReceived(err, file) { - function onFileReceived(err, file) { + try { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Entering function."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> key = " + pDevTeam.codeName + "-" + pBot.codeName + "-" + pProduct.codeName); } switch (err.result) { case GLOBAL.DEFAULT_OK_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received OK Response."); } break; } case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received FAIL Response."); } callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); return; } + case GLOBAL.CUSTOM_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM OK Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); } - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> err.message = " + err.message); } callBackFunction(err); return; @@ -123,20 +87,80 @@ function newFileSequence() { default: { - if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> Received Unexpected Response."); } callBackFunction(err); return; } } - files.set(i, file); + maxSequence = Number(file); - filesLoaded++; + /* Now we will get the sequence of files */ - callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the callback is called for every file loaded. + for (let i = 0; i <= maxSequence; i++) { + fileCloud.getFile(pDevTeam, pBot, pSet, exchange, pMarket, undefined, undefined, i, onFileReceived); + + function onFileReceived(err, file) { + + try { + + switch (err.result) { + case GLOBAL.DEFAULT_OK_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received OK Response."); } + break; + } + + case GLOBAL.DEFAULT_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received FAIL Response."); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE); + return; + } + + case GLOBAL.CUSTOM_FAIL_RESPONSE.result: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received CUSTOM FAIL Response."); } + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> err.message = " + err.message); } + + callBackFunction(err); + return; + } + + default: { + + if (INFO_LOG === true) { logger.write("[INFO] initialize -> onSequenceFileReceived -> onFileReceived -> Received Unexpected Response."); } + callBackFunction(err); + return; + } + } + + files.set(i, file); + + filesLoaded++; + + callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, thisObject); // Note that the callback is called for every file loaded. + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> onFileReceived -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); + } + } + } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> onSequenceFileReceived -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } + + } catch (err) { + + if (ERROR_LOG === true) { logger.write("[ERROR] initialize -> err = " + err); } + callBackFunction(GLOBAL.CUSTOM_FAIL_RESPONSE); } } diff --git a/server.js b/server.js index 1cf8bb361..330817bd6 100644 --- a/server.js +++ b/server.js @@ -6,7 +6,7 @@ if (CONSOLE_LOG === true) { } -const DEBUG_MODE = false; // This forces the server to read Plotters from the local drive. +const DEBUG_MODE = true; // This forces the server to read Plotters from the local drive. if (CONSOLE_LOG === true && DEBUG_MODE === true) {