osteele / liquid

A Liquid template engine in Go
https://godoc.org/github.com/osteele/liquid
MIT License
287 stars 59 forks source link

Panic when using WrapError(), Errorf() or SourceFile() in a block #80

Closed wttw closed 1 year ago

wttw commented 1 year ago

Checklist

Detailed Description

If a custom block, created with RegisterBlock(), uses render.Context.WrapError it panics due to render.rendererContext.node being nil.

Errorf() and SourceFile() have the same issue.

Test case:

package main

import (
    "errors"
    "github.com/osteele/liquid"
    "github.com/osteele/liquid/render"
)

func main() {
    engine := liquid.NewEngine()
    engine.RegisterBlock("foo", func(c render.Context) (string, error) {
        return "bar", c.WrapError(errors.New("baz"))
    })
    _, _ = engine.ParseAndRenderString(`{% foo %}  {% endfoo %}`, map[string]interface{}{})

}

Possible Solution