From 9c31dc4f0a5b0b2aa0ebd96d5e69f0699fc117f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Wed, 20 Mar 2024 13:07:49 +0100 Subject: [PATCH 1/3] [jet] raise error occured in embed() --- jet/jet.go | 13 +++++++++---- jet/jet_test.go | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/jet/jet.go b/jet/jet.go index 3d60e80..0e12e5f 100644 --- a/jet/jet.go +++ b/jet/jet.go @@ -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 } return tmpl.Execute(out, bind, nil) } diff --git a/jet/jet_test.go b/jet/jet_test.go index 0d22d76..712910b 100644 --- a/jet/jet_test.go +++ b/jet/jet_test.go @@ -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) +} + func Test_Empty_Layout(t *testing.T) { t.Parallel() engine := New("./views", ".jet") From 913c1a20669faf1119a1cd7beaa39e35bc04928e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Wed, 20 Mar 2024 13:12:53 +0100 Subject: [PATCH 2/3] Fix spacing --- jet/jet.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jet/jet.go b/jet/jet.go index 0e12e5f..b04df9b 100644 --- a/jet/jet.go +++ b/jet/jet.go @@ -179,13 +179,13 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout return err } var renderingError error - bind.Set(e.LayoutName, func() { + bind.Set(e.LayoutName, func() { renderingError = tmpl.Execute(out, bind, nil) - }) - err = lay.Execute(out, bind, nil) - if renderingError != nil { + }) + err = lay.Execute(out, bind, nil) + if renderingError != nil { return renderingError - } + } return err } return tmpl.Execute(out, bind, nil) From b1963117ca1bd24e73df9eb7b06d6de8e5b1905a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= Date: Wed, 20 Mar 2024 13:14:32 +0100 Subject: [PATCH 3/3] Fix spacing --- jet/jet.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jet/jet.go b/jet/jet.go index b04df9b..edb3510 100644 --- a/jet/jet.go +++ b/jet/jet.go @@ -178,15 +178,15 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout if err != nil { return err } - var renderingError error + var renderingError error bind.Set(e.LayoutName, func() { - renderingError = tmpl.Execute(out, bind, nil) + renderingError = tmpl.Execute(out, bind, nil) }) err = lay.Execute(out, bind, nil) if renderingError != nil { - return renderingError + return renderingError } - return err + return err } return tmpl.Execute(out, bind, nil) }