From 4991e14dff8d31bfa69f5abe77ea5b4200617123 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sun, 3 Jan 2021 12:05:04 +0800 Subject: [PATCH] improve error message when failed in Mkdir --- os/gfile/gfile.go | 5 ++--- os/glog/glog_logger_config.go | 3 ++- os/gsession/gsession_storage_file.go | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/os/gfile/gfile.go b/os/gfile/gfile.go index b1be677d8..fa8596060 100644 --- a/os/gfile/gfile.go +++ b/os/gfile/gfile.go @@ -59,10 +59,9 @@ func init() { } // Mkdir creates directories recursively with given . -// The parameter is suggested to be absolute path. +// The parameter is suggested to be an absolute path instead of relative one. func Mkdir(path string) error { - err := os.MkdirAll(path, os.ModePerm) - if err != nil { + if err := os.MkdirAll(path, os.ModePerm); err != nil { return err } return nil diff --git a/os/glog/glog_logger_config.go b/os/glog/glog_logger_config.go index f9cbea08c..924a9e2e4 100644 --- a/os/glog/glog_logger_config.go +++ b/os/glog/glog_logger_config.go @@ -9,6 +9,7 @@ package glog import ( "errors" "fmt" + "github.com/gogf/gf/errors/gerror" "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/os/gfile" "github.com/gogf/gf/util/gconv" @@ -191,7 +192,7 @@ func (l *Logger) SetPath(path string) error { if !gfile.Exists(path) { if err := gfile.Mkdir(path); err != nil { //fmt.Fprintln(os.Stderr, fmt.Sprintf(`[glog] mkdir "%s" failed: %s`, path, err.Error())) - return err + return gerror.Wrapf(err, `Mkdir "%s" failed in Pwd "%s"`, path, gfile.Pwd()) } } l.config.Path = strings.TrimRight(path, gfile.Separator) diff --git a/os/gsession/gsession_storage_file.go b/os/gsession/gsession_storage_file.go index 5a4a4a247..a256b0eec 100644 --- a/os/gsession/gsession_storage_file.go +++ b/os/gsession/gsession_storage_file.go @@ -9,6 +9,7 @@ package gsession import ( "fmt" "github.com/gogf/gf/container/gmap" + "github.com/gogf/gf/errors/gerror" "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/internal/json" "os" @@ -55,7 +56,7 @@ func NewStorageFile(path ...string) *StorageFile { } if storagePath != "" { if err := gfile.Mkdir(storagePath); err != nil { - panic(fmt.Sprintf("mkdir '%s' failed: %v", path[0], err)) + panic(gerror.Wrapf(err, `Mkdir "%s" failed in Pwd "%s"`, path, gfile.Pwd())) } } s := &StorageFile{