From 378c0b207ed588e93e1f023b5e2cae76a0f29ef7 Mon Sep 17 00:00:00 2001 From: Oliver Steele Date: Mon, 10 Jul 2017 11:52:14 -0400 Subject: [PATCH] Update remaining public API to return SourceError --- engine.go | 6 +++--- liquid.go | 2 ++ template.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/engine.go b/engine.go index 1fd6545..3b77471 100644 --- a/engine.go +++ b/engine.go @@ -71,12 +71,12 @@ func (e *Engine) RegisterTag(name string, td Renderer) { } // ParseTemplate creates a new Template using the engine configuration. -func (e *Engine) ParseTemplate(source []byte) (*Template, error) { +func (e *Engine) ParseTemplate(source []byte) (*Template, SourceError) { return newTemplate(&e.cfg, source) } // ParseAndRender parses and then renders the template. -func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, error) { +func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, SourceError) { tpl, err := e.ParseTemplate(source) if err != nil { return nil, err @@ -85,7 +85,7 @@ func (e *Engine) ParseAndRender(source []byte, b Bindings) ([]byte, error) { } // ParseAndRenderString is a convenience wrapper for ParseAndRender, that takes string input and returns a string. -func (e *Engine) ParseAndRenderString(source string, b Bindings) (string, error) { +func (e *Engine) ParseAndRenderString(source string, b Bindings) (string, SourceError) { bs, err := e.ParseAndRender([]byte(source), b) if err != nil { return "", err diff --git a/liquid.go b/liquid.go index 211ad39..063c944 100644 --- a/liquid.go +++ b/liquid.go @@ -39,6 +39,8 @@ type SourceError interface { // are likely to change. func IsTemplateError(err error) bool { switch err.(type) { + // TODO some of these clauses, or maybe the entire function, is unnecessary + // now that interface calls return SourceError case evaluator.TypeError: return true case expression.InterpreterError: diff --git a/template.go b/template.go index 96f727d..1aa3dcc 100644 --- a/template.go +++ b/template.go @@ -23,7 +23,7 @@ func newTemplate(cfg *render.Config, source []byte) (*Template, SourceError) { } // Render executes the template with the specified variable bindings. -func (t *Template) Render(vars Bindings) ([]byte, error) { +func (t *Template) Render(vars Bindings) ([]byte, SourceError) { buf := new(bytes.Buffer) err := render.Render(t.root, buf, vars, *t.config) if err != nil { @@ -33,7 +33,7 @@ func (t *Template) Render(vars Bindings) ([]byte, error) { } // RenderString is a convenience wrapper for Render, that has string input and output. -func (t *Template) RenderString(b Bindings) (string, error) { +func (t *Template) RenderString(b Bindings) (string, SourceError) { bs, err := t.Render(b) if err != nil { return "", err