From a8c72398ba56352d08f00a9958d36bde9b0cd71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Cruz?= Date: Tue, 29 Jan 2013 15:07:25 +0000 Subject: [PATCH] Better error messages for invalid bowerrc files, closes #220. --- lib/core/config.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/core/config.js b/lib/core/config.js index 7dfe7050..427e3363 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -23,19 +23,28 @@ var folder = process.platform === 'win32' : '.bower'; // Bower Config -var config = require('rc') ('bower', { - cache : path.join(roaming, folder, 'cache'), - links : path.join(roaming, folder, 'links'), - completion : path.join(roaming, folder, 'completion'), - json : 'component.json', - endpoint : 'https://bower.herokuapp.com', - directory : 'components' -}); +var config; +try { + config = require('rc') ('bower', { + cache : path.join(roaming, folder, 'cache'), + links : path.join(roaming, folder, 'links'), + completion : path.join(roaming, folder, 'completion'), + json : 'component.json', + endpoint : 'https://bower.herokuapp.com', + directory : 'components' + }); +} catch (e) { + throw new Error('Unable to parse global .bowerrc file: ' + e.message); +} // If there is a local .bowerrc file, merge it var localFile = path.join(this.cwd, '.bowerrc'); if (fileExists(localFile)) { - _.extend(config, JSON.parse(fs.readFileSync(localFile))); + try { + _.extend(config, JSON.parse(fs.readFileSync(localFile))); + } catch (e) { + throw new Error('Unable to parse local .bowerrc file: ' + e.message); + } } // Configure tmp package to use graceful degradationn