From 84fd066e2c17624d3bf63ce65be0480fbe56a93f Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Wed, 13 Nov 2019 07:26:09 -0800 Subject: [PATCH] entc: return an error if template was not found (#160) Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/160 Code was failing due to nil pointer in case of unknown template Reviewed By: alexsn Differential Revision: D18477913 fbshipit-source-id: 5c93e9697c5d62cbb9a0a6955231aa133c52f6db --- entc/entc.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/entc/entc.go b/entc/entc.go index e5ac82022..9707bdb46 100644 --- a/entc/entc.go +++ b/entc/entc.go @@ -7,6 +7,7 @@ package entc import ( + "fmt" "os" "path" "path/filepath" @@ -112,11 +113,13 @@ func TemplateGlob(pattern string) Option { // and associates the resulting templates with codegen templates. func TemplateDir(path string) Option { return templateOption(func(cfg *gen.Config) error { - return filepath.Walk(path, func(path string, info os.FileInfo, _ error) error { + return filepath.Walk(path, func(path string, info os.FileInfo, err error) error { + if err != nil { + return fmt.Errorf("load template: %v", err) + } if info.IsDir() { return nil } - var err error cfg.Template, err = cfg.Template.ParseFiles(path) return err })