Skip to content

Commit 2b06453

Browse files
diogogmtannismckenzie
authored andcommitted
Raising a panic in the includeIfExists helper when templates does exist but fails to render.
1 parent 3272189 commit 2b06453

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

default.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ func init() {
8383

8484
a.RequireNumOfArguments("includeIfExists", 1, 2)
8585
t, err := a.runtime.set.GetTemplate(a.Get(0).String())
86+
// If template exists but returns an error then panic instead of failing silently
87+
if t != nil && err != nil {
88+
panic(err)
89+
}
8690
if err != nil {
8791
return hiddenFALSE
8892
}

eval_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,17 @@ func TestIncludeIfNotExists(t *testing.T) {
364364
RunJetTestWithSet(t, set, nil, nil, "notExistent", "", "")
365365
RunJetTestWithSet(t, set, nil, nil, "ifIncludeIfExits", "", "Hi, i exist!!\n Was included!!\n\n\n Was not included!!\n\n")
366366
RunJetTestWithSet(t, set, nil, "World", "wcontext", "", "Hi, Buddy!\nHi, World!")
367+
368+
// Check if includeIfExists helper bubbles up runtime errors of included templates
369+
tt, err := set.GetTemplate("includeBroken")
370+
if err != nil {
371+
t.Error(err)
372+
}
373+
buff := bytes.NewBuffer(nil)
374+
err = tt.Execute(buff, nil, nil)
375+
if err == nil {
376+
t.Error("expected includeIfExists helper to fail with a runtime error but got nil")
377+
}
367378
}
368379

369380
func TestSet_Parse(t *testing.T) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ err.break }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{ includeIfExists: "broken.jet"}}

0 commit comments

Comments
 (0)