diff --git a/Changes.md b/Changes.md index 615c210..45707a4 100644 --- a/Changes.md +++ b/Changes.md @@ -1,31 +1,36 @@ +# 1.0.10 - 2017-02-05 + +- log error vs throw on bad YAML +- fix appveyor badge URL + # 1.0.9 - 2017-01-27 - - config cache fix (see haraka/Haraka#1738) - - config: add overrides handling (sync with Haraka) - - configfile: add win64 watching (sync with Haraka) - - remove grunt - - use haraka-eslint plugin (vs local copy of .eslintrc) - - lint updates +- config cache fix (see haraka/Haraka#1738) +- config: add overrides handling (sync with Haraka) +- configfile: add win64 watching (sync with Haraka) +- remove grunt +- use haraka-eslint plugin (vs local copy of .eslintrc) +- lint updates # 1.0.8 - 2017-01-02 - * version bump, lint updates & sync - * lint fixes +- version bump, lint updates & sync +- lint fixes # 1.0.7 - 2016-11-17 - * update tests for appveyor (Windows) compatibility #9 +- update tests for appveyor (Windows) compatibility #9 # 1.0.6 - 2016-11-10 - * handle invalid .ini lines properly (skip them) +- handle invalid .ini lines properly (skip them) # 1.0.5 - 2016-10-25 - * do not leave behind a `*` section in config (due to wildcard boolean) +- do not leave behind a `*` section in config (due to wildcard boolean) # 1.0.3 - * added wildcard boolean support - * reduce node required 4.3 -> 0.10.43 +- added wildcard boolean support +- reduce node required 4.3 -> 0.10.43 diff --git a/README.md b/README.md index 96dd67d..64d3b94 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Coverage Status][cov-img]][cov-url] [![Code Climate][clim-img]][clim-url] [![Windows Build status][apv-img]][apv-url] -[![Greenkeeper badge](https://badges.greenkeeper.io/haraka/haraka-config.svg)](https://greenkeeper.io/) +[![Greenkeeper badge][gk-img]][gk-url] # haraka-config @@ -23,7 +23,7 @@ Haraka's config loader can load several types of configuration files. * 'binary' - load a binary file into a Buffer See the [File Formats](#file_formats) section below for a more detailed -explaination of each of the formats. +explanation of each of the formats. # Usage @@ -46,9 +46,7 @@ an update is detected on the file after the configuration cache has been updated by re-reading the file. Use this to refresh configuration variables within your plugin. Example: -`````javascript -var cfg; // variable global to this plugin only - +```js exports.register = function () { var plugin = this; plugin.loginfo('register function called'); @@ -57,7 +55,7 @@ exports.register = function () { exports.load_my_plugin_ini = function () { var plugin = this; - plugin.cfg = plugin.config.get('my_plugin.ini', function onIniChange () { + plugin.cfg = plugin.config.get('my_plugin.ini', function onCfgChange () { // This closure is run a few milliseconds after my_plugin.ini changes // Re-run the outer function again plugin.load_my_plugin_ini(); @@ -68,7 +66,7 @@ exports.load_my_plugin_ini = function () { exports.hook_connect = function (next, connection) { // plugin.cfg in here will always be up-to-date } -````` +``` The `options` object can accepts the following keys: @@ -291,5 +289,7 @@ Haraka will be unable to update them after changes. [cov-url]: https://codecov.io/github/haraka/haraka-config?branch=master [clim-img]: https://codeclimate.com/github/haraka/haraka-config/badges/gpa.svg [clim-url]: https://codeclimate.com/github/haraka/haraka-config -[apv-img]: https://ci.appveyor.com/api/projects/status/lme4otppxe22me0j/branch/master?svg=true +[apv-img]: https://ci.appveyor.com/api/projects/status/9qh720gq77e2h5x4?svg=true [apv-url]: https://ci.appveyor.com/project/msimerson/haraka-config/branch/master +[gk-img]: https://badges.greenkeeper.io/haraka/haraka-config.svg +[gk-url]: https://greenkeeper.io/ diff --git a/configfile.js b/configfile.js index 134d7b9..803d02a 100644 --- a/configfile.js +++ b/configfile.js @@ -297,10 +297,11 @@ cfreader.load_config = function (name, type, options) { cfreader._config_cache[cache_key] = result; } catch (err) { - if (err.code !== 'EBADF') throw err; + console.error(err.message); if (cfreader._config_cache[cache_key]) { - result = cfreader._config_cache[cache_key]; + return cfreader._config_cache[cache_key]; } + return cfrType.empty(options, type); } return result; }; diff --git a/package.json b/package.json index 63c0c7a..3386c60 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "haraka-config", "license": "MIT", "description": "Haraka's config file loader", - "version": "1.0.9", + "version": "1.0.10", "homepage": "http://haraka.github.io", "repository": { "type": "git", diff --git a/test/config/bad.yaml b/test/config/bad.yaml new file mode 100644 index 0000000..b1a52da --- /dev/null +++ b/test/config/bad.yaml @@ -0,0 +1,6 @@ +blacklist: + - subject: dcdresptest + body: \nT\[: 0-9 -.\] DEBUG.*SetError + - subject: regex2 +whitelist: + - subject: dcdresptest\.1 \ No newline at end of file diff --git a/test/configfile.js b/test/configfile.js index e0c023d..8d7f433 100644 --- a/test/configfile.js +++ b/test/configfile.js @@ -372,3 +372,13 @@ exports.regex = { test.done(); }, } + +exports.bad_config = { + setUp: _set_up, + 'bad.yaml returns empty' : function (test) { + test.expect(1); + var res = this.cfreader.load_config('test/config/bad.yaml'); + test.deepEqual(res, {}); + test.done(); + }, +} diff --git a/test/readers/binary.js b/test/readers/binary.js index 8dcd161..2a343c8 100644 --- a/test/readers/binary.js +++ b/test/readers/binary.js @@ -19,17 +19,6 @@ exports.load = { test.ok(typeof this.bin.load === 'function'); test.done(); }, - 'throws when file is non-existent': function (test) { - test.expect(2); - try { - this.bin.load('test/config/non-existent.bin'); - } - catch (e) { - test.equal(e.code, 'ENOENT'); - test.ok(/no such file or dir/.test(e.message)); - } - test.done(); - }, 'loads the test binary file': function (test) { test.expect(3); var testBin = 'test/config/test.binary'; diff --git a/test/readers/flat.js b/test/readers/flat.js index ead8d67..e3f534d 100644 --- a/test/readers/flat.js +++ b/test/readers/flat.js @@ -19,17 +19,6 @@ exports.load = { test.ok(typeof this.flat.load === 'function'); test.done(); }, - 'throws when file is non-existent': function (test) { - test.expect(2); - try { - this.flat.load('test/config/non-existent.flat'); - } - catch (e) { - test.equal(e.code, 'ENOENT'); - test.ok(/no such file or dir/.test(e.message)); - } - test.done(); - }, 'loads the test flat file, as list': function (test) { test.expect(1); var result = this.flat.load( diff --git a/test/readers/json.js b/test/readers/json.js index 4c2a9b1..36e85eb 100644 --- a/test/readers/json.js +++ b/test/readers/json.js @@ -17,17 +17,6 @@ exports.load = { test.ok(typeof this.json.load === 'function'); test.done(); }, - 'throws when file is non-existent': function (test) { - test.expect(2); - try { - this.json.load('test/config/non-existent.json'); - } - catch (e) { - test.equal(e.code, 'ENOENT'); - test.ok(/no such file or dir/.test(e.message)); - } - test.done(); - }, 'loads the test JSON file': function (test) { test.expect(3); var result = this.json.load('test/config/test.json'); diff --git a/test/readers/yaml.js b/test/readers/yaml.js index 37c14fb..e046dd6 100644 --- a/test/readers/yaml.js +++ b/test/readers/yaml.js @@ -17,21 +17,9 @@ exports.load = { test.ok(typeof this.yaml.load === 'function'); test.done(); }, - 'throws when file is non-existent': function (test) { - test.expect(2); - try { - this.yaml.load('test/config/non-existent.haml'); - } - catch (e) { - test.equal(e.code, 'ENOENT'); - test.ok(/no such file or dir/.test(e.message)); - } - test.done(); - }, 'loads the test yaml file': function (test) { test.expect(4); var result = this.yaml.load('test/config/test.yaml'); - // console.log(result); test.strictEqual(result.main.bool_true, true); test.equal(result.matt, 'waz here'); test.ok(result.array.length);