Skip to content

Commit

Permalink
Improve error-message when partial is missing
Browse files Browse the repository at this point in the history
Signed-off-by: Seyed Mohammad Mahdi Hatami <hatamik7@gmail.com>
  • Loading branch information
smmhatami authored and jaylinski committed Aug 31, 2023
1 parent d3b9357 commit 8ce2be4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ export function invokePartial(partial, context, options) {
}

if (partial === undefined) {
throw new Exception('The partial ' + options.name + ' could not be found');
throw new Exception(
'The partial "' + options.name + '" could not be found'
);
} else if (partial instanceof Function) {
return partial(context, options);
}
Expand Down
11 changes: 7 additions & 4 deletions spec/partials.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ describe('partials', function () {
return 'missing';
})
.withPartial('dude', '{{name}} ({{url}}) ')
.toThrow(Handlebars.Exception, 'The partial missing could not be found');
.toThrow(
Handlebars.Exception,
'The partial "missing" could not be found'
);
});

it('partials with context', function () {
Expand Down Expand Up @@ -156,7 +159,7 @@ describe('partials', function () {
it('rendering undefined partial throws an exception', function () {
expectTemplate('{{> whatever}}').toThrow(
Handlebars.Exception,
'The partial whatever could not be found'
'The partial "whatever" could not be found'
);
});

Expand All @@ -174,7 +177,7 @@ describe('partials', function () {
it('rendering template partial in vm mode throws an exception', function () {
expectTemplate('{{> whatever}}').toThrow(
Handlebars.Exception,
'The partial whatever could not be found'
'The partial "whatever" could not be found'
);
});

Expand Down Expand Up @@ -472,7 +475,7 @@ describe('partials', function () {

expectTemplate(
'{{#with .}}{{#*inline "myPartial"}}success{{/inline}}{{/with}}{{> myPartial}}'
).toThrow(Error, /myPartial could not/);
).toThrow(Error, /"myPartial" could not/);
});

it('should override global partials', function () {
Expand Down

0 comments on commit 8ce2be4

Please sign in to comment.