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. 26
      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
}
// 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

@ -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 = "<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

@ -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 = "<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")
}

Loading…
Cancel
Save