From 5f1df2792fe0e051744285435e266175edb8545f Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 20 Aug 2015 21:25:29 -0700 Subject: [PATCH] Better error handling for config.json problems --- app.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 72ecef4..235f53e 100644 --- a/app.js +++ b/app.js @@ -9,11 +9,12 @@ var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); -console.log("====================================================================="); +console.log("_____________________________________________________________________"); console.log("IMPORTANT: Homebridge is in the middle of some big changes."); console.log(" Read more about it here:"); console.log(" https://github.com/nfarina/homebridge/wiki/Migration-Guide"); -console.log("====================================================================="); +console.log("_____________________________________________________________________"); +console.log(""); // Look for the configuration file var configPath = path.join(__dirname, "config.json"); @@ -28,7 +29,14 @@ if (!fs.existsSync(configPath)) { hap.init(); // Load up the configuration file -var config = JSON.parse(fs.readFileSync(configPath)); +var config; +try { + config = JSON.parse(fs.readFileSync(configPath)); +} +catch (err) { + console.log("There was a problem reading your config.json file:\n\n" + err.stack); + process.exit(0); +} // pull out our custom Bridge settings from config.json, if any var bridgeConfig = config.bridge || {};