Skip to content

Commit

Permalink
Raising a panic in the includeIfExists helper when templates does exi…
Browse files Browse the repository at this point in the history
…st but fails to render.
  • Loading branch information
diogogmt authored and annismckenzie committed Nov 4, 2017
1 parent 3272189 commit 2b06453
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions default.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func init() {

a.RequireNumOfArguments("includeIfExists", 1, 2)
t, err := a.runtime.set.GetTemplate(a.Get(0).String())
// If template exists but returns an error then panic instead of failing silently
if t != nil && err != nil {
panic(err)
}
if err != nil {
return hiddenFALSE
}
Expand Down
11 changes: 11 additions & 0 deletions eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ func TestIncludeIfNotExists(t *testing.T) {
RunJetTestWithSet(t, set, nil, nil, "notExistent", "", "")
RunJetTestWithSet(t, set, nil, nil, "ifIncludeIfExits", "", "Hi, i exist!!\n Was included!!\n\n\n Was not included!!\n\n")
RunJetTestWithSet(t, set, nil, "World", "wcontext", "", "Hi, Buddy!\nHi, World!")

// Check if includeIfExists helper bubbles up runtime errors of included templates
tt, err := set.GetTemplate("includeBroken")
if err != nil {
t.Error(err)
}
buff := bytes.NewBuffer(nil)
err = tt.Execute(buff, nil, nil)
if err == nil {
t.Error("expected includeIfExists helper to fail with a runtime error but got nil")
}
}

func TestSet_Parse(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions testData/includeIfNotExists/broken.jet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ err.break }}
1 change: 1 addition & 0 deletions testData/includeIfNotExists/includeBroken.jet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ includeIfExists: "broken.jet"}}

0 comments on commit 2b06453

Please sign in to comment.