Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
add error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlacy committed Aug 5, 2014
1 parent 04d269c commit 6ebb29a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function(opts) {
try {
content = JSON.parse(json);
} catch (e) {
return cb(new gutil.PluginError('gulp-bump', 'Problem parsing JSON file ' + file.path));
return cb(new gutil.PluginError('gulp-bump', 'Problem parsing JSON file', {fileName: file.path, showStack: true}));
}

// just set a version to the key
Expand All @@ -68,7 +68,7 @@ module.exports = function(opts) {
content[key] = semver.inc(content[key], type);
}
else {
return cb(new gutil.PluginError('gulp-bump', 'Detected invalid semver ' + key + ' in file ' + file.path));
return cb(new gutil.PluginError('gulp-bump', 'Detected invalid semver ' + key, {fileName: file.path, showStack: false}));
}
file.contents = new Buffer(JSON.stringify(content, null, indent || space(json)) + possibleNewline(json));

Expand Down
15 changes: 10 additions & 5 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,37 @@ describe('gulp-bump', function() {

bumpS.on('error', function(e) {
should.exist(e);
e.name.should.equal('Error');
e.message.should.containEql('Detected invalid semver version in file ' + file);
e.message.should.equal('Detected invalid semver version');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should fail when not detect a valid semver version and wrong key', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
contents: new Buffer('{ "version": "0.0.1" }')
path: file,
contents: new Buffer('{ "version": "0.0.1" }')
});

var bumpS = bump({key: 'appversion'});

bumpS.on('error', function(e) {
should.exist(e);
e.name.should.equal('Error');
e.message.should.containEql('Detected invalid semver appversion in file');
e.message.should.containEql('Detected invalid semver appversion');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
bumpS.end();
});

it('should fail when supplied with an invalid JSON', function(done) {
var file = 'some-dir/dummyfile.js';
var fakeFile = new gutil.File({
path: file,
contents: new Buffer('{ invalid json oh no!!!}')
});

Expand All @@ -164,6 +168,7 @@ describe('gulp-bump', function() {
should.exist(e);
e.name.should.equal('Error');
e.message.should.containEql('Problem parsing JSON file');
e.fileName.should.containEql(file);
return done();
});
bumpS.write(fakeFile);
Expand Down

0 comments on commit 6ebb29a

Please sign in to comment.