diff --git a/cmd/config/errors-utils.go b/cmd/config/errors-utils.go index 2847cf3ec..c242db9df 100644 --- a/cmd/config/errors-utils.go +++ b/cmd/config/errors-utils.go @@ -36,6 +36,16 @@ type Err struct { hint string } +// Clone returns a new Err struct with the same information +func (u Err) Clone() Err { + return Err{ + msg: u.msg, + detail: u.detail, + action: u.action, + hint: u.hint, + } +} + // Return the error message func (u Err) Error() string { if u.detail == "" { @@ -49,12 +59,16 @@ func (u Err) Error() string { // Msg - Replace the current error's message func (u Err) Msg(m string, args ...interface{}) Err { - return Err{ - msg: fmt.Sprintf(m, args...), - detail: u.detail, - action: u.action, - hint: u.hint, - } + e := u.Clone() + e.msg = fmt.Sprintf(m, args...) + return e +} + +// Hint - Replace the current error's message +func (u Err) Hint(m string, args ...interface{}) Err { + e := u.Clone() + e.hint = fmt.Sprintf(m, args...) + return e } // ErrFn function wrapper diff --git a/cmd/fs-v1.go b/cmd/fs-v1.go index 683e4df2c..f9e65fd51 100644 --- a/cmd/fs-v1.go +++ b/cmd/fs-v1.go @@ -20,10 +20,12 @@ import ( "bytes" "context" "errors" + "fmt" "io" "io/ioutil" "net/http" "os" + "os/user" "path" "path/filepath" "sort" @@ -129,7 +131,15 @@ func NewFSObjectLayer(fsPath string) (ObjectLayer, error) { if err == errMinDiskSize { return nil, err } - return nil, config.ErrUnableToWriteInBackend(err) + // Show a descriptive error with a hint about how to fix it. + var username string + if u, err := user.Current(); err == nil { + username = u.Username + } else { + username = "" + } + hint := fmt.Sprintf("Use 'sudo chown %s %s && sudo chmod u+rxw %s' to provide sufficient permissions.", username, fsPath, fsPath) + return nil, config.ErrUnableToWriteInBackend(err).Hint(hint) } // Assign a new UUID for FS minio mode. Each server instance diff --git a/cmd/storage-rest-server.go b/cmd/storage-rest-server.go index 2a60b5d1e..3cf0c5783 100644 --- a/cmd/storage-rest-server.go +++ b/cmd/storage-rest-server.go @@ -24,6 +24,7 @@ import ( "fmt" "io" "net/http" + "os/user" "path" "strconv" "strings" @@ -608,7 +609,16 @@ func registerStorageRESTHandlers(router *mux.Router, endpointZones EndpointZones } storage, err := newPosix(endpoint.Path) if err != nil { - logger.Fatal(config.ErrUnableToWriteInBackend(err), + // Show a descriptive error with a hint about how to fix it. + var username string + if u, err := user.Current(); err == nil { + username = u.Username + } else { + username = "" + } + hint := fmt.Sprintf("Run the following command to add the convenient permissions: `sudo chown %s %s && sudo chmod u+rxw %s`", + username, endpoint.Path, endpoint.Path) + logger.Fatal(config.ErrUnableToWriteInBackend(err).Hint(hint), "Unable to initialize posix backend") }