Better error when the server is unable to write in the backend (#8697)

master
Anis Elleuch 5 years ago committed by kannappanr
parent cd59a945d8
commit c31e67dcce
  1. 24
      cmd/config/errors-utils.go
  2. 12
      cmd/fs-v1.go
  3. 12
      cmd/storage-rest-server.go

@ -36,6 +36,16 @@ type Err struct {
hint string 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 // Return the error message
func (u Err) Error() string { func (u Err) Error() string {
if u.detail == "" { if u.detail == "" {
@ -49,12 +59,16 @@ func (u Err) Error() string {
// Msg - Replace the current error's message // Msg - Replace the current error's message
func (u Err) Msg(m string, args ...interface{}) Err { func (u Err) Msg(m string, args ...interface{}) Err {
return Err{ e := u.Clone()
msg: fmt.Sprintf(m, args...), e.msg = fmt.Sprintf(m, args...)
detail: u.detail, return e
action: u.action,
hint: u.hint,
} }
// 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 // ErrFn function wrapper

@ -20,10 +20,12 @@ import (
"bytes" "bytes"
"context" "context"
"errors" "errors"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
"os/user"
"path" "path"
"path/filepath" "path/filepath"
"sort" "sort"
@ -129,7 +131,15 @@ func NewFSObjectLayer(fsPath string) (ObjectLayer, error) {
if err == errMinDiskSize { if err == errMinDiskSize {
return nil, err 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 = "<your-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 // Assign a new UUID for FS minio mode. Each server instance

@ -24,6 +24,7 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"os/user"
"path" "path"
"strconv" "strconv"
"strings" "strings"
@ -608,7 +609,16 @@ func registerStorageRESTHandlers(router *mux.Router, endpointZones EndpointZones
} }
storage, err := newPosix(endpoint.Path) storage, err := newPosix(endpoint.Path)
if err != nil { 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 = "<your-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") "Unable to initialize posix backend")
} }

Loading…
Cancel
Save