Skip to content

Commit

Permalink
improve TypeError message
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Jan 23, 2018
1 parent 39f63ed commit 390d469
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const {inspect} = require('util');

const assertValidGlobOpts = require('assert-valid-glob-opts');
const fsCacheableRealpath = require('fs.realpath/old.js').realpath;
const fsOriginalRealpath = require('graceful-fs').realpath;
const Glob = require('glob').Glob;
const {Glob} = require('glob');
const inspectWithKind = require('inspect-with-kind');
const {makeAbs} = require('glob/common.js');
const Observable = require('zen-observable');

Expand All @@ -22,7 +21,9 @@ module.exports = function globObservable(...args) {
const [pattern] = args;

if (typeof pattern !== 'string') {
throw new TypeError(`Expected a glob pattern string, but got ${inspect(pattern)}.`);
throw new TypeError(`Expected a glob pattern (<string>), but got a non-string value ${
inspectWithKind(pattern)
}.`);
}

if (argLen === 2) {
Expand Down Expand Up @@ -51,7 +52,7 @@ module.exports = function globObservable(...args) {
changedCwd: glob.changedCwd,
cwd: glob.cwd,
// glob.root affects the result of makeAbs
// https://github.com/isaacs/node-glob/blob/v7.1.1/common.js#L206
// https://github.com/isaacs/node-glob/blob/v7.1.2/common.js#L206
root: ''
};

Expand Down
19 changes: 10 additions & 9 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 @@ -30,6 +30,7 @@
"fs.realpath": "^1.0.0",
"glob": "^7.1.2",
"graceful-fs": "^4.1.11",
"inspect-with-kind": "^1.0.4",
"zen-observable": "^0.7.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ test('globObservable()', async t => {
error({message}) {
t.equal(
message,
'Expected a glob pattern string, but got <Buffer 68 69>.',
'Expected a glob pattern (<string>), but got a non-string value <Buffer 68 69>.',
'should fail when it takes a non-string glob pattern.'
);
},
Expand Down

0 comments on commit 390d469

Please sign in to comment.