From 68b0bd98fd6ac7942fb0a2313ed79750bc66bb90 Mon Sep 17 00:00:00 2001 From: Viktor Vassilyev Date: Tue, 6 Nov 2018 20:41:05 +0600 Subject: [PATCH] fix(Template): error handling when reading files --- fs.go | 7 +++++++ template.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/fs.go b/fs.go index 905be9fb..11b7e9be 100644 --- a/fs.go +++ b/fs.go @@ -40,6 +40,13 @@ func walk(fs http.FileSystem, path string, info os.FileInfo, walkFn filepath.Wal dir, err := fs.Open(path) defer dir.Close() + if err == nil { + err1 := walkFn(path, info, err) + if err1 != nil { + return err1 + } + return err + } dirs, err := dir.Readdir(-1) err1 := walkFn(path, info, err) // If err != nil, walk can't walk into this directory. diff --git a/template.go b/template.go index f8589445..24f98e5a 100644 --- a/template.go +++ b/template.go @@ -327,6 +327,10 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod } data, err = ioutil.ReadAll(f) f.Close() + if err != nil { + logs.Trace("template parse file err:", err) + continue + } reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"") allSub := reg.FindAllStringSubmatch(string(data), -1) for _, sub := range allSub { @@ -337,6 +341,9 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod logs.Trace("template parse file err:", err) } else if len(subMods1) > 0 { t, err = _getTemplate(t, root, fs, subMods1, others...) + if err != nil { + logs.Trace("template parse file err:", err) + } } break }