From c794c46f6dab5461ebeb9cf5498871047c95c44c Mon Sep 17 00:00:00 2001 From: Seyed Mohammad Mahdi Hatami Date: Thu, 29 Jun 2023 00:54:40 +0330 Subject: [PATCH] Improve error-message when partial is missing Signed-off-by: Seyed Mohammad Mahdi Hatami --- lib/handlebars/runtime.js | 4 +++- spec/partials.js | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index 1c7cc4cc..2a33f7bc 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -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); } diff --git a/spec/partials.js b/spec/partials.js index 5144b424..4bb52d11 100644 --- a/spec/partials.js +++ b/spec/partials.js @@ -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 () { @@ -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' ); }); @@ -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' ); }); @@ -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 () {