Skip to content

Commit

Permalink
improve TypeError message
Browse files Browse the repository at this point in the history
by using `inspect-with-kind`

https://github.com/shinnn/inspect-with-kind
  • Loading branch information
shinnn committed Dec 27, 2017
1 parent 6a9ca31 commit 8ef1270
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
'use strict';

const frontMatter = require('front-matter');
const inspectWithKind = require('inspect-with-kind');
const objectPath = require('object-path');
const PluginError = require('plugin-error');
const Transform = require('stream').Transform;
const VinylBufferStream = require('vinyl-bufferstream');

const PROPERTY_ERROR = 'Expected `property` option to be a string';

module.exports = function gulpFrontMatter(options) {
options = Object.assign({property: 'frontMatter'}, options);

if (typeof options.property !== 'string') {
throw new PluginError('gulp-front-matter', new TypeError(`${
options.property
} is not a string. "property" option must be a string.`));
throw new PluginError('gulp-front-matter', new TypeError(`${PROPERTY_ERROR}, but a non-string value ${
inspectWithKind(options.property)
} was provided.`));
}

return new Transform({
Expand Down
21 changes: 18 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"license": "BSD-2-Clause",
"dependencies": {
"front-matter": "^2.3.0",
"inspect-with-kind": "^1.0.4",
"object-path": "^0.11.4",
"plugin-error": "^0.1.2",
"vinyl-bufferstream": "^1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test('gulp-front-matter', t => {

t.throws(
() => gulpFrontMatter({property: 1}),
/.*is not a string.*must be a string/,
/Expected `property` option to be a string, but a non-string value 1 \(number\) was provided\./,
'should throw a plugin error when `property` option is not a string.'
);
});

0 comments on commit 8ef1270

Please sign in to comment.