Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jet] raise error occured in embed() #365

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions jet/jet.go
Original file line number Diff line number Diff line change
@@ -178,10 +178,15 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
if err != nil {
return err
}
bind.Set(e.LayoutName, func() {
err = tmpl.Execute(out, bind, nil)
})
return lay.Execute(out, bind, nil)
var renderingError error
bind.Set(e.LayoutName, func() {
renderingError = tmpl.Execute(out, bind, nil)
})
err = lay.Execute(out, bind, nil)
if renderingError != nil {
return renderingError
}
return err
ReneWerner87 marked this conversation as resolved.
Show resolved Hide resolved
}
return tmpl.Execute(out, bind, nil)
}
13 changes: 13 additions & 0 deletions jet/jet_test.go
Original file line number Diff line number Diff line change
@@ -62,6 +62,19 @@ func Test_Layout(t *testing.T) {
require.Equal(t, expect, result)
}

func Test_Layout_Error(t *testing.T) {
t.Parallel()
engine := New("./views", ".jet")

require.NoError(t, engine.Load())

var buf bytes.Buffer
err := engine.Render(&buf, "index", map[string]interface{}{
// "Title": "Hello, World!",
}, "layouts/main")
require.NotNil(t, err)
}
ReneWerner87 marked this conversation as resolved.
Show resolved Hide resolved

func Test_Empty_Layout(t *testing.T) {
t.Parallel()
engine := New("./views", ".jet")
Loading