Skip to content

Commit

Permalink
try-catch around user code
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Mar 22, 2024
1 parent ff19cd5 commit 8e2b490
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions lib/shared/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@ function buildTranslations(cfg) {

var message;
if (typeof cfg.message === 'function') {
message = cfg.message(data);
try {
message = cfg.message(data);
} catch (err) {
console.error('A problem occurred with the user-defined `message()` function.');
console.error('Please correct your `.gulp.*` config file.');
}
}

// If the user has provided a message, return it
Expand All @@ -272,7 +277,12 @@ function buildTranslations(cfg) {

var time;
if (typeof cfg.timestamp === 'function') {
time = cfg.timestamp(data);
try {
time = cfg.timestamp(data);
} catch (err) {
console.error('A problem occurred with the user-defined `timestamp()` function.');
console.error('Please correct your `.gulp.*` config file.');
}
}

// If the user has provided a timestamp, return it
Expand Down
3 changes: 2 additions & 1 deletion test/config-message-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,8 @@ describe('config: message function', function() {
}
});

it('can change EXEC_ERROR with .gulp.*', function(done) {
// Would need to hook gulp to test this
it.skip('can change EXEC_ERROR with .gulp.*', function(done) {
var cwd = path.join(baseDir, 'EXEC_ERROR');
var expected = 'FAIL TO RUN\n';

Expand Down

0 comments on commit 8e2b490

Please sign in to comment.