Commit 68b0bd98 authored by Viktor Vassilyev's avatar Viktor Vassilyev

fix(Template): error handling when reading files

parent 34477984
...@@ -40,6 +40,13 @@ func walk(fs http.FileSystem, path string, info os.FileInfo, walkFn filepath.Wal ...@@ -40,6 +40,13 @@ func walk(fs http.FileSystem, path string, info os.FileInfo, walkFn filepath.Wal
dir, err := fs.Open(path) dir, err := fs.Open(path)
defer dir.Close() defer dir.Close()
if err == nil {
err1 := walkFn(path, info, err)
if err1 != nil {
return err1
}
return err
}
dirs, err := dir.Readdir(-1) dirs, err := dir.Readdir(-1)
err1 := walkFn(path, info, err) err1 := walkFn(path, info, err)
// If err != nil, walk can't walk into this directory. // If err != nil, walk can't walk into this directory.
......
...@@ -327,6 +327,10 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod ...@@ -327,6 +327,10 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod
} }
data, err = ioutil.ReadAll(f) data, err = ioutil.ReadAll(f)
f.Close() f.Close()
if err != nil {
logs.Trace("template parse file err:", err)
continue
}
reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"") reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"")
allSub := reg.FindAllStringSubmatch(string(data), -1) allSub := reg.FindAllStringSubmatch(string(data), -1)
for _, sub := range allSub { for _, sub := range allSub {
...@@ -337,6 +341,9 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod ...@@ -337,6 +341,9 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod
logs.Trace("template parse file err:", err) logs.Trace("template parse file err:", err)
} else if len(subMods1) > 0 { } else if len(subMods1) > 0 {
t, err = _getTemplate(t, root, fs, subMods1, others...) t, err = _getTemplate(t, root, fs, subMods1, others...)
if err != nil {
logs.Trace("template parse file err:", err)
}
} }
break break
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment