improve error message when failed in Mkdir

This commit is contained in:
John Guo 2021-01-03 12:05:04 +08:00
parent 5629020538
commit 4991e14dff
3 changed files with 6 additions and 5 deletions

View File

@ -59,10 +59,9 @@ func init() {
}
// Mkdir creates directories recursively with given <path>.
// The parameter <path> is suggested to be absolute path.
// The parameter <path> 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

View File

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

View File

@ -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{