diff --git a/src/generator.js b/src/generator.js index 7ec005b..f2c6f80 100644 --- a/src/generator.js +++ b/src/generator.js @@ -4,6 +4,8 @@ * @typedef {import('./parse-data')} ParseData */ +const sprintf = require('sprintf-js').sprintf; + class Generator { constructor() { /** @@ -93,7 +95,7 @@ class Generator { */ _getBranch(name) { if (this._branches.has(name) === false) { - throw new Error('Branch not created: ' + name); + throw new Error(sprintf('A branch named \'%s\' not created.', name)); } return this._branches.get(name); diff --git a/src/grammar-support/branch-list.js b/src/grammar-support/branch-list.js index 5fb1c67..f92303e 100644 --- a/src/grammar-support/branch-list.js +++ b/src/grammar-support/branch-list.js @@ -1,3 +1,4 @@ +const sprintf = require('sprintf-js').sprintf; const Branch = require('./branch'); /** @@ -18,7 +19,7 @@ class BranchList { */ add(branch) { if (this._branches.has(branch)) { - throw new Error('Branch already exists: ' + branch); + throw new Error(sprintf('A branch named \'%s\' already exists.', branch)); } this._branches.set(branch, new Branch(branch)); @@ -31,7 +32,7 @@ class BranchList { */ get(branch) { if (!this._branches.has(branch)) { - throw new Error('Branch not created: ' + branch); + throw new Error(sprintf('A branch named \'%s\' not created.', branch)); } return this._branches.get(branch); diff --git a/src/grammar-support/tag-list.js b/src/grammar-support/tag-list.js index 635e949..ef0d557 100644 --- a/src/grammar-support/tag-list.js +++ b/src/grammar-support/tag-list.js @@ -1,3 +1,5 @@ +const sprintf = require('sprintf-js').sprintf; + class TagList { constructor() { /** @@ -13,7 +15,7 @@ class TagList { */ add(tag) { if (this._tags.has(tag)) { - throw new Error('Tag already exists: ' + tag); + throw new Error(sprintf('Tag \'%s\' already exists.', tag)); } this._tags.add(tag); diff --git a/test/input_error_semantics.js b/test/input_error_semantics.js index 9d5ddfa..7e3e755 100644 --- a/test/input_error_semantics.js +++ b/test/input_error_semantics.js @@ -73,7 +73,7 @@ module.exports = [ git branch foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 02', @@ -85,7 +85,7 @@ module.exports = [ git checkout -b foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 03', @@ -97,7 +97,7 @@ module.exports = [ git switch -c foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 04', @@ -109,7 +109,7 @@ module.exports = [ git branch foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 05', @@ -121,7 +121,7 @@ module.exports = [ git checkout -b foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 06', @@ -133,7 +133,7 @@ module.exports = [ git switch -c foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 07', @@ -145,7 +145,7 @@ module.exports = [ git branch foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 08', @@ -157,7 +157,7 @@ module.exports = [ git checkout -b foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 09', @@ -169,7 +169,7 @@ module.exports = [ git switch -c foo `, line: 6, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 10', @@ -180,7 +180,7 @@ module.exports = [ git branch foo `, line: 5, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 11', @@ -191,7 +191,7 @@ module.exports = [ git checkout -b foo `, line: 5, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, { case: 'create branch - already created - 12', @@ -202,7 +202,7 @@ module.exports = [ git switch -c foo `, line: 5, - message: 'Branch already exists: foo', + message: "A branch named 'foo' already exists.", }, // merge - branch not created @@ -213,7 +213,7 @@ module.exports = [ git merge foo `, line: 3, - message: 'Branch not created: foo', + message: "A branch named 'foo' not created.", }, { case: 'merge - branch not created - 02', @@ -223,7 +223,7 @@ module.exports = [ git merge foo `, line: 4, - message: 'Branch not created: foo', + message: "A branch named 'foo' not created.", }, // merge - no commits on branch @@ -287,7 +287,7 @@ module.exports = [ git tag v1 `, line: 5, - message: 'Tag already exists: v1', + message: "Tag 'v1' already exists.", }, { case: 'tag - already exists - 02', @@ -299,7 +299,7 @@ module.exports = [ git tag v1 `, line: 6, - message: 'Tag already exists: v1', + message: "Tag 'v1' already exists.", }, // tag - no commits on branch