Cleanup minio, remote struct printing for Info, Error and Fatal - simplifying overall error handling

This commit is contained in:
Harshavardhana
2015-07-14 11:02:04 -07:00
parent 1aa3496142
commit d4047ca899
18 changed files with 112 additions and 315 deletions
+6 -27
View File
@@ -65,47 +65,26 @@ func runAccessCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: "loading config file failed",
Error: iodine.New(err, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() {
console.Fatals(ErrorMessage{
Message: "Valid types are [private, public, readonly].",
Error: iodine.New(errInvalidACL{acl: acl.String()}, nil),
})
console.Fatalf("Valid types are [private, public, readonly]. %s\n", errInvalidACL{acl: acl.String()})
}
for _, arg := range ctx.Args().Tail() {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: iodine.New(e, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
msg, err := doUpdateAccessCmd(targetURL, acl)
if err != nil {
console.Errors(ErrorMessage{
Message: msg,
Error: iodine.New(err, nil),
})
console.Fatalln(msg)
}
console.Infoln(msg)
}
+5 -24
View File
@@ -17,7 +17,6 @@
package main
import (
"fmt"
"io"
"os"
"syscall"
@@ -66,41 +65,23 @@ func runCatCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
// Convert arguments to URLs: expand alias, fix format...
for _, arg := range ctx.Args() {
sourceURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: iodine.New(e, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
errorMsg, err := doCatCmd(sourceURL)
if err != nil {
console.Fatals(ErrorMessage{
Message: errorMsg,
Error: iodine.New(err, nil),
})
console.Fatalln(errorMsg)
}
}
}
+2 -8
View File
@@ -65,17 +65,11 @@ func runConfigCmd(ctx *cli.Context) {
arg := ctx.Args().First()
tailArgs := ctx.Args().Tail()
if len(tailArgs) > 2 {
console.Fatals(ErrorMessage{
Message: "Incorrect number of arguments, please use \"mc config help\"",
Error: iodine.New(errInvalidArgument{}, nil),
})
console.Fatalf("Incorrect number of arguments, please use \"mc config help\". %s", errInvalidArgument{})
}
msg, err := doConfig(arg, tailArgs)
if err != nil {
console.Fatals(ErrorMessage{
Message: msg,
Error: iodine.New(err, nil),
})
console.Fatalln(msg)
}
console.Infoln(msg)
}
+10 -15
View File
@@ -90,7 +90,7 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup
var newReader io.ReadCloser
if globalQuietFlag || globalJSONFlag {
console.Infos(CopyMessage{
console.Infoln(CopyMessage{
Source: cpURLs.SourceContent.Name,
Target: cpURLs.TargetContent.Name,
Length: cpURLs.SourceContent.Size,
@@ -144,20 +144,14 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if cpURLs.Error != nil {
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(cpURLs.Error, nil),
})
console.Errorln(cpURLs.Error)
break
}
jsonData, err := json.Marshal(cpURLs)
if err != nil {
session.Close()
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to marshal URLs to JSON for ‘%s’", cpURLs.SourceContent.Name),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to marshal URLs to JSON. %s\n", err)
}
fmt.Fprintln(dataFP, string(jsonData))
scanBar(cpURLs.SourceContent.Name)
@@ -225,18 +219,19 @@ func runCopyCmd(ctx *cli.Context) {
session := newSessionV2()
defer session.Close()
var err error
session.Header.CommandType = "cp"
session.Header.RootPath, _ = os.Getwd()
session.Header.RootPath, err = os.Getwd()
if err != nil {
session.Close()
console.Fatalf("Unable to get current working directory. %s\n", err)
}
// extract URLs.
var err error
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown URL types found: ‘%s’", ctx.Args()),
Error: iodine.New(err, nil),
})
console.Fatalf("One or more unknown URL types found %s. %s\n", ctx.Args(), err)
}
doCopyCmdSession(session)
+11 -39
View File
@@ -17,8 +17,6 @@
package main
import (
"fmt"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
@@ -59,65 +57,39 @@ func runDiffCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
firstURL := ctx.Args().First()
secondURL := ctx.Args()[1]
var err error
firstURL, err = getExpandedURL(firstURL, config.Aliases)
if err != nil {
switch iodine.ToError(err).(type) {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
Error: iodine.New(err, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", firstURL, err)
}
}
secondURL, err = getExpandedURL(secondURL, config.Aliases)
if err != nil {
switch iodine.ToError(err).(type) {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
Error: iodine.New(err, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", secondURL, err)
}
}
if isURLRecursive(secondURL) {
console.Fatals(ErrorMessage{
Message: "Second URL cannot be recursive, diff command is unidirectional",
Error: iodine.New(errInvalidArgument{}, nil),
})
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument{})
}
newFirstURL := stripRecursiveURL(firstURL)
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
if diff.err != nil {
console.Fatals(ErrorMessage{
Message: diff.message,
Error: iodine.New(diff.err, nil),
})
console.Fatalln(diff.message)
}
console.Infoln(diff.message)
}
+5 -26
View File
@@ -17,8 +17,6 @@
package main
import (
"fmt"
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
@@ -84,43 +82,24 @@ func runListCmd(ctx *cli.Context) {
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config, err := getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
}
config := mustGetMcConfig()
for _, arg := range args {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: iodine.New(e, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
// if recursive strip off the "..."
newTargetURL := stripRecursiveURL(targetURL)
err = doListCmd(newTargetURL, isURLRecursive(targetURL))
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
Error: iodine.New(err, map[string]string{"Target": targetURL}),
})
console.Fatalln("Failed to list : %s. %s\n", targetURL, err)
}
}
}
+5 -23
View File
@@ -61,40 +61,22 @@ func runMakeBucketCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
}
config, err := getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: "Unable to read config file ‘" + mustGetMcConfigPath() + "’",
Error: iodine.New(err, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
config := mustGetMcConfig()
for _, arg := range ctx.Args() {
targetURL, err := getExpandedURL(arg, config.Aliases)
if err != nil {
switch e := iodine.ToError(err).(type) {
case errUnsupportedScheme:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
Error: iodine.New(e, nil),
})
console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
default:
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
}
}
msg, err := doMakeBucketCmd(targetURL)
if err != nil {
console.Errors(ErrorMessage{
Message: msg,
Error: iodine.New(err, nil),
})
console.Fatalln(msg)
}
console.Infoln(msg)
}
+6 -24
View File
@@ -108,10 +108,7 @@ func runSessionCmd(ctx *cli.Context) {
}
if !isSessionDirExists() {
if err := createSessionDir(); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to create session directory. %s\n", err)
}
}
switch strings.TrimSpace(ctx.Args().First()) {
@@ -119,10 +116,7 @@ func runSessionCmd(ctx *cli.Context) {
case "list":
err := listSessions()
if err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Fatalln(err)
}
case "resume":
if len(ctx.Args().Tail()) != 1 {
@@ -136,26 +130,17 @@ func runSessionCmd(ctx *cli.Context) {
_, err := os.Stat(getSessionFile(sid))
if err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(errInvalidSessionID{id: sid}, nil),
})
console.Fatalln(errInvalidSessionID{id: sid})
}
s, err := loadSessionV2(sid)
if err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(errInvalidSessionID{id: sid}, nil),
})
console.Fatalln(errInvalidSessionID{id: sid})
}
savedCwd, err := os.Getwd()
if err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Fatalln("Unable to verify your current working directory. %s\n", err)
}
if s.Header.RootPath != "" {
// chdir to RootPath
@@ -165,10 +150,7 @@ func runSessionCmd(ctx *cli.Context) {
sessionExecute(s)
err = s.Close()
if err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Fatalln("Unable to close session file properly. %s\n", err)
}
// change dir back
+12 -20
View File
@@ -28,7 +28,6 @@ import (
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
)
// Help message.
@@ -84,10 +83,7 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou
if !globalQuietFlag || !globalJSONFlag {
bar.ErrorGet(int64(length))
}
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Errorf("Unable to read from source %s. %s\n", sURLs.SourceContent.Name, err)
}
var targetURLs []string
@@ -97,7 +93,7 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou
var newReader io.ReadCloser
if globalQuietFlag || globalJSONFlag {
console.Infos(SyncMessage{
console.Infoln(SyncMessage{
Source: sURLs.SourceContent.Name,
Targets: targetURLs,
})
@@ -113,6 +109,7 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou
if !globalQuietFlag || !globalJSONFlag {
bar.ErrorPut(int64(length))
}
console.Errorf("Unable to write to one or many destinations. %s\n", err)
}
}
return nil
@@ -147,20 +144,14 @@ func doPrepareSyncURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if sURLs.Error != nil {
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(sURLs.Error, nil),
})
console.Errorln(sURLs.Error)
break
}
jsonData, err := json.Marshal(sURLs)
if err != nil {
session.Close()
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to marshal URLs to JSON for ‘%s’", sURLs.SourceContent.Name),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to marshal URLs to JSON. %s\n", err)
}
fmt.Fprintln(dataFP, string(jsonData))
scanBar(sURLs.SourceContent.Name)
@@ -227,18 +218,19 @@ func runSyncCmd(ctx *cli.Context) {
session := newSessionV2()
defer session.Close()
var err error
session.Header.CommandType = "sync"
session.Header.RootPath, _ = os.Getwd()
session.Header.RootPath, err = os.Getwd()
if err != nil {
session.Close()
console.Fatalf("Unable to get current working directory. %s\n", err)
}
// extract URLs.
var err error
session.Header.CommandArgs, err = args2URLs(ctx.Args())
if err != nil {
session.Close()
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unknown URL types found: ‘%s’", ctx.Args()),
Error: iodine.New(err, nil),
})
console.Fatalf("One or more unknown URL types found in %s. %s\n", ctx.Args(), err)
}
doSyncCmdSession(session)
+2 -8
View File
@@ -105,17 +105,11 @@ func runUpdateCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
}
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
msg, err := doUpdateCheck()
if err != nil {
console.Fatals(ErrorMessage{
Message: msg,
Error: iodine.New(err, nil),
})
console.Fatalln(msg)
}
// no msg do not print one
if msg != "" {
+2 -1
View File
@@ -52,7 +52,6 @@ func (s *CmdTestSuite) SetUpSuite(c *C) {
// For windows the path is slightly different.
if runtime.GOOS == "windows" {
customConfigDir = filepath.Join(tmpDir, mcConfigWindowsDir)
} else {
customConfigDir = filepath.Join(tmpDir, mcConfigDir)
}
@@ -73,6 +72,8 @@ func (s *CmdTestSuite) TearDownSuite(c *C) {
func (s *CmdTestSuite) TestGetNewClient(c *C) {
_, err := getNewClient("http://example.com/bucket1", &hostConfig{})
c.Assert(err, IsNil)
_, err = getNewClient("https://example.com/bucket1", &hostConfig{})
c.Assert(err, IsNil)
_, err = getNewClient("C:\\Users\\Administrator\\MyDocuments", &hostConfig{})
c.Assert(err, IsNil)
_, err = getNewClient("/usr/bin/pandoc", &hostConfig{})
+22 -2
View File
@@ -50,7 +50,6 @@ func getMcConfigDir() (string, error) {
if mcCustomConfigDir != "" {
return mcCustomConfigDir, nil
}
u, err := user.Current()
if err != nil {
return "", iodine.New(err, nil)
@@ -97,7 +96,10 @@ func getMcConfigPath() (string, error) {
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
func mustGetMcConfigPath() string {
p, _ := getMcConfigPath()
p, err := getMcConfigPath()
if err != nil {
console.Fatalf("Unable to determine default config path. %s\n", err)
}
return p
}
@@ -132,6 +134,15 @@ func getMcConfig() (*configV1, error) {
}
// mustGetMcConfig - reads configuration file and returns configs, exits on error
func mustGetMcConfig() *configV1 {
config, err := getMcConfig()
if err != nil {
console.Fatalf("Unable to retrieve mc configuration. %s\n", err)
}
return config
}
// isMcConfigExists xreturns err if config doesn't exist
func isMcConfigExists() bool {
configFile, err := getMcConfigPath()
@@ -210,3 +221,12 @@ func newConfig() (config quick.Config, err error) {
return config, nil
}
// mustNewConfig instantiates a new config handler, exists upon error
func mustNewConfig() quick.Config {
config, err := newConfig()
if err != nil {
console.Fatalf("Unable to instantiate a new config handler. %s\n", err)
}
return config
}
+10
View File
@@ -21,6 +21,7 @@ import (
"strings"
"github.com/minio/mc/pkg/client"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
)
@@ -69,3 +70,12 @@ func getHostConfig(URL string) (*hostConfig, error) {
}
return nil, iodine.New(errNoMatchingHost{}, nil)
}
// mustGetHostConfig retrieves host specific configuration such as access keys, exits upon error
func mustGetHostConfig(URL string) *hostConfig {
hostCfg, err := getHostConfig(URL)
if err != nil {
console.Fatalf("Unable to retrieve host configuration. %s\n", err)
}
return hostCfg
}
+2 -8
View File
@@ -79,17 +79,11 @@ func doList(clnt client.Client, recursive bool) error {
switch err := iodine.ToError(contentCh.Err).(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Errorf(err.Error())
continue
}
if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
console.Errors(ErrorMessage{
Message: "Failed with",
Error: iodine.New(contentCh.Err, nil),
})
console.Errorf(contentCh.Err.Error())
continue
}
err = contentCh.Err
+7 -24
View File
@@ -25,7 +25,6 @@ import (
"github.com/minio/cli"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
"github.com/minio/pb"
)
@@ -33,10 +32,7 @@ import (
func checkConfig() {
_, err := user.Current()
if err != nil {
console.Fatals(ErrorMessage{
Message: "Unable to determine current user",
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to determine current user. %s\n", err)
}
// If config doesn't exist, do not attempt to read it
@@ -47,10 +43,7 @@ func checkConfig() {
// Ensures config file is sane
_, err = getMcConfig()
if err != nil {
console.Fatals(ErrorMessage{
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to read config file. %s\n", err)
}
}
@@ -59,7 +52,7 @@ func checkConfig() {
func getSystemData() map[string]string {
host, err := os.Hostname()
if err != nil {
host = ""
console.Fatalf("Unable to determine hostname. %s\n", err)
}
memstats := &runtime.MemStats{}
runtime.ReadMemStats(memstats)
@@ -133,19 +126,12 @@ func main() {
themeName := ctx.GlobalString("theme")
switch {
case console.IsValidTheme(themeName) != true:
err := iodine.New(errInvalidTheme{Theme: themeName}, nil)
console.Errors(ErrorMessage{
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
Error: iodine.New(err, nil),
})
return err
console.Errorf("Invalid theme, please choose from the following list: %s.\n", console.GetThemeNames())
return errInvalidTheme{Theme: themeName}
default:
err := console.SetTheme(themeName)
if err != nil {
console.Errors(ErrorMessage{
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
Error: iodine.New(err, nil),
})
console.Errorf("Failed to set theme ‘%s’.", themeName)
return err
}
}
@@ -154,10 +140,7 @@ func main() {
}
app.After = func(ctx *cli.Context) error {
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
return nil
}
-18
View File
@@ -126,13 +126,6 @@ var (
return
}
// Fatals print a error structure with a new line and exit
Fatals = func(data ...interface{}) {
defer os.Exit(1)
println(themesDB[currThemeName].Error, data...)
return
}
// Error prints a error message
Error = func(data ...interface{}) {
print(themesDB[currThemeName].Error, data...)
@@ -151,11 +144,6 @@ var (
return
}
// Errors print a error structure with a new line
Errors = func(data ...interface{}) {
println(themesDB[currThemeName].Error, data...)
}
// Info prints a informational message
Info = func(data ...interface{}) {
print(themesDB[currThemeName].Info, data...)
@@ -174,12 +162,6 @@ var (
return
}
// Infos print a informational structured message
Infos = func(data ...interface{}) {
println(themesDB[currThemeName].Info, data...)
return
}
// Debug prints a debug message without a new line
// Debug prints a debug message
Debug = func(data ...interface{}) {
-30
View File
@@ -22,38 +22,8 @@ import (
"fmt"
"github.com/minio/mc/pkg/console"
"github.com/minio/minio/pkg/iodine"
)
// ErrorMessage container for error reason encapsulation
type ErrorMessage struct {
Message string `json:"-"`
Error error `json:"error"`
}
// String string printer for error message
func (e ErrorMessage) String() string {
if !globalJSONFlag {
var message string
if e.Error != nil {
switch e.Error.(type) {
case iodine.Error:
reason := iodine.ToError(e.Error).Error()
message = reason
default:
reason := e.Error.Error()
message = reason
}
}
return message
}
eBytes, err := json.Marshal(iodine.ToError(e.Error))
if err != nil {
panic(err)
}
return string(eBytes)
}
// Content container for content message structure
type Content struct {
Filetype string `json:"type"`
+5 -18
View File
@@ -65,18 +65,12 @@ type sessionV2 struct {
func newSessionV2() *sessionV2 {
// TODO: Blindly create .mc and session dirs at init and remove these checks -ab.
if !isMcConfigExists() {
console.Fatals(ErrorMessage{
Message: "Please run \"mc config generate\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
}
if !isSessionDirExists() {
if err := createSessionDir(); err != nil {
console.Fatals(ErrorMessage{
Message: "Failed with",
Error: iodine.New(err, nil),
})
console.Fatalf("Unable to create session directory. %s\n", err)
}
}
@@ -91,12 +85,8 @@ func newSessionV2() *sessionV2 {
var err error
s.DataFP, err = os.Create(getSessionDataFile(s.SessionID))
if err != nil {
console.Fatals(ErrorMessage{
Message: "Unable to create session data file \"" + getSessionDataFile(s.SessionID) + "\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Unable to create session data file \""+getSessionDataFile(s.SessionID)+"\". %s\n", err)
}
return s
}
@@ -202,10 +192,7 @@ func loadSessionV2(sid string) (*sessionV2, error) {
s.DataFP, err = os.Open(getSessionDataFile(s.SessionID))
if err != nil {
console.Fatals(ErrorMessage{
Message: "Unable to open session data file \"" + getSessionDataFile(s.SessionID) + "\"",
Error: iodine.New(errNotConfigured{}, nil),
})
console.Fatalf("Unable to open session data file \""+getSessionDataFile(s.SessionID)+"\". %s", errNotConfigured{})
}
return s, nil
@@ -218,7 +205,7 @@ func isCopiedFactory(lastCopied string) func(string) bool {
copied := true // closure
return func(sourceURL string) bool {
if sourceURL == "" {
console.Fatalln("Empty source URL passed to isCopied() function. Please report this bug.")
console.Fatalf("Empty source URL passed to isCopied() function. %s\n", errUnexpected{})
}
if lastCopied == "" {
return false