From d2a1c18e8a99150524e165b42044f3f406d567ba Mon Sep 17 00:00:00 2001 From: danbulant Date: Wed, 19 Feb 2020 17:54:12 +0100 Subject: [PATCH] Add exception handling --- index.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index bc2e3a7..cad4b22 100644 --- a/index.js +++ b/index.js @@ -5,22 +5,29 @@ var console = new Console; var pkg = new Package; const VERSION = "0.1" +process.on('uncaughtException', function (err) { + console.error("Uncaught exception:", err.message); + console.error(err.stack); +}); + +process.on('unhandledRejection', function (reason, p) { + console.warn("Possibly Unhandled Rejection, reason: ", reason); +}); + if(!args.contents[0]){ return console.output(`BPM v${VERSION}\nMade by Daniel Bulant`); } switch(args.contents[0]){ - case "i": - case "install": - console.warn("To be done"); - break; case "get": case "info": - pkg.get(args.contents[1]).then(console.log); + pkg.get(args.contents[1]).catch(console.error); break; case "bin": console.log(__dirname); break; + case "i": + case "install": case "ls": case "help": case "ping":