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
This commit is contained in:
Ariel Mashraki
2019-11-13 07:26:09 -08:00
committed by Facebook Github Bot
parent 6ce4cb6803
commit 84fd066e2c

View File

@@ -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
})