Skip to content

Commit

Permalink
log vs throw bad YAML error (#16)
Browse files Browse the repository at this point in the history
* log vs throw bad YAML error
  • Loading branch information
msimerson committed Feb 6, 2017
1 parent 2650e5b commit 3ab1d7c
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 69 deletions.
31 changes: 18 additions & 13 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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');
Expand All @@ -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();
Expand All @@ -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:

Expand Down Expand Up @@ -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/
5 changes: 3 additions & 2 deletions configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions test/config/bad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
blacklist:
- subject: dcdresptest
body: \nT\[: 0-9 -.\] DEBUG.*SetError
- subject: regex2
whitelist:
- subject: dcdresptest\.1
10 changes: 10 additions & 0 deletions test/configfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
}
11 changes: 0 additions & 11 deletions test/readers/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
11 changes: 0 additions & 11 deletions test/readers/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions test/readers/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
12 changes: 0 additions & 12 deletions test/readers/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3ab1d7c

Please sign in to comment.