1
0
mirror of https://github.com/minio/mc.git synced 2025-11-14 23:42:27 +03:00

Prefix error messages with mc: part of #286

This commit is contained in:
Harshavardhana
2015-04-16 15:53:21 -07:00
parent 0702f392ba
commit 0935573255
9 changed files with 46 additions and 36 deletions

View File

@@ -352,7 +352,7 @@ func saveConfigCmd(ctx *cli.Context) {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("mc: Unable to identify config file path") console.Fatalln("mc: Unable to identify config file path")
} }
console.Infoln("Configuration written to " + configPath + ". Please update your access credentials.") console.Infoln("mc: Configuration written to " + configPath + ". Please update your access credentials.")
} }
// doConfigCmd is the handler for "mc config" sub-command. // doConfigCmd is the handler for "mc config" sub-command.
@@ -362,7 +362,7 @@ func doConfigCmd(ctx *cli.Context) {
case ctx.Bool("completion") == true: case ctx.Bool("completion") == true:
var b bytes.Buffer var b bytes.Buffer
if os.Getenv("SHELL") != "/bin/bash" { if os.Getenv("SHELL") != "/bin/bash" {
console.Fatalln("Unsupported shell for bash completion detected.. exiting") console.Fatalln("mc: Unsupported shell for bash completion detected.. exiting")
} }
b.WriteString(mcBashCompletion) b.WriteString(mcBashCompletion)
f, err := getMcBashCompletionFilename() f, err := getMcBashCompletionFilename()
@@ -374,12 +374,12 @@ func doConfigCmd(ctx *cli.Context) {
defer fl.Close() defer fl.Close()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to create bash completion file") console.Fatalln("mc: Unable to create bash completion file")
} }
_, err = fl.Write(b.Bytes()) _, err = fl.Write(b.Bytes())
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to write bash completion file") console.Fatalln("mc: Unable to write to bash completion file")
} }
msg := "\nConfiguration written to " + f msg := "\nConfiguration written to " + f
msg = msg + "\n\n$ source ${HOME}/.mc/mc.bash_completion\n" msg = msg + "\n\n$ source ${HOME}/.mc/mc.bash_completion\n"

View File

@@ -84,7 +84,7 @@ func doCopyCmd(ctx *cli.Context) {
urlParsers, err := parseURLs(ctx) urlParsers, err := parseURLs(ctx)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to parse URL") console.Fatalln("mc: Unable to parse URL")
} }
sourceURLParser := urlParsers[0] // First arg is source sourceURLParser := urlParsers[0] // First arg is source
targetURLsParser := urlParsers[1:] // 1 or more targets targetURLsParser := urlParsers[1:] // 1 or more targets
@@ -92,13 +92,13 @@ func doCopyCmd(ctx *cli.Context) {
reader, length, hexMd5, err := getSourceReader(sourceURLParser) reader, length, hexMd5, err := getSourceReader(sourceURLParser)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to read source") console.Fatalln("mc: Unable to read source")
} }
writeClosers, err := getTargetWriters(targetURLsParser, hexMd5, length) writeClosers, err := getTargetWriters(targetURLsParser, hexMd5, length)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to open targets for writing") console.Fatalln("mc: Unable to open targets for writing")
} }
var writers []io.Writer var writers []io.Writer
@@ -125,11 +125,11 @@ func doCopyCmd(ctx *cli.Context) {
err := writer.Close() err := writer.Close()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Errorln("Unable to close writer, object may not of written properly.") console.Errorln("mc: Unable to close writer, object may not of written properly.")
} }
} }
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to write to target") console.Fatalln("mc: Unable to write to target")
} }
} }

View File

@@ -63,18 +63,18 @@ func doListCmd(ctx *cli.Context) {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to get config") console.Fatalln("mc: Unable to get config")
} }
for _, arg := range ctx.Args() { for _, arg := range ctx.Args() {
targetURLParser, err := parseURL(arg, config.Aliases) targetURLParser, err := parseURL(arg, config.Aliases)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to parse URL") console.Fatalln("mc: Unable to parse URL")
} }
client, err := getNewClient(targetURLParser, globalDebugFlag) client, err := getNewClient(targetURLParser, globalDebugFlag)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to initiate new client") console.Fatalln("mc: Unable to initiate new client")
} }
// ListBuckets() will not be called for fsClient() as its not needed. // ListBuckets() will not be called for fsClient() as its not needed.
@@ -82,14 +82,14 @@ func doListCmd(ctx *cli.Context) {
buckets, err := client.ListBuckets() buckets, err := client.ListBuckets()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to list buckets for", targetURLParser.String()) console.Fatalln("mc: Unable to list buckets for ", targetURLParser.String())
} }
printBuckets(buckets) printBuckets(buckets)
} else { } else {
items, err = client.ListObjects(targetURLParser.bucketName, targetURLParser.objectName) items, err = client.ListObjects(targetURLParser.bucketName, targetURLParser.objectName)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to list objects for", targetURLParser.String()) console.Fatalln("mc: Unable to list objects for ", targetURLParser.String())
} }
printObjects(items) printObjects(items)
} }

View File

@@ -32,13 +32,13 @@ func doMakeBucketCmd(ctx *cli.Context) {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to get config") console.Fatalln("mc: Unable to read config")
} }
for _, arg := range ctx.Args() { for _, arg := range ctx.Args() {
targetURLParser, err := parseURL(arg, config.Aliases) targetURLParser, err := parseURL(arg, config.Aliases)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to parse URL:", arg) console.Fatalln("mc: Unable to parse URL: ", arg)
} }
// this is handled differently since http based URLs cannot have // this is handled differently since http based URLs cannot have
// nested directories as buckets, buckets are a unique alphanumeric // nested directories as buckets, buckets are a unique alphanumeric
@@ -46,13 +46,13 @@ func doMakeBucketCmd(ctx *cli.Context) {
if targetURLParser.urlType != urlFile { if targetURLParser.urlType != urlFile {
if !client.IsValidBucketName(targetURLParser.bucketName) { if !client.IsValidBucketName(targetURLParser.bucketName) {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("Invalid bucket name: %s", targetURLParser.bucketName) console.Fatalf("mc: Invalid bucket name: %s", targetURLParser.bucketName)
} }
} }
clnt, err := getNewClient(targetURLParser, globalDebugFlag) clnt, err := getNewClient(targetURLParser, globalDebugFlag)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("Unable to create new client to: %s", targetURLParser.String()) console.Fatalf("mc: Unable to create new client to: %s", targetURLParser.String())
} }
err = clnt.PutBucket(targetURLParser.bucketName) err = clnt.PutBucket(targetURLParser.bucketName)
if err != nil { if err != nil {

View File

@@ -62,7 +62,7 @@ func doCopyCmdRecursive(ctx *cli.Context) {
urlParsers, err := parseURLs(ctx) urlParsers, err := parseURLs(ctx)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln(err) console.Fatalf("mc: unable to parse urls: %s\n", err)
} }
sourceURLParser := urlParsers[0] // First arg is source sourceURLParser := urlParsers[0] // First arg is source
targetURLParser := urlParsers[1] // 1 target for now - TODO(y4m4): 2 or more targets targetURLParser := urlParsers[1] // 1 target for now - TODO(y4m4): 2 or more targets
@@ -70,24 +70,24 @@ func doCopyCmdRecursive(ctx *cli.Context) {
sourceClnt, err := getNewClient(sourceURLParser, globalDebugFlag) sourceClnt, err := getNewClient(sourceURLParser, globalDebugFlag)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln(err) console.Fatalf("mc: unable to get source: %s\n", err)
} }
sourceObjectList, err := getSourceObjectList(sourceClnt, sourceURLParser) sourceObjectList, err := getSourceObjectList(sourceClnt, sourceURLParser)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln(err) console.Fatalf("mc: unable to list source objects: %s\n", err)
} }
// do not exit, continue even for failures // do not exit, continue even for failures
for _, sourceObject := range sourceObjectList { for _, sourceObject := range sourceObjectList {
reader, length, md5hex, err := sourceClnt.Get(sourceURLParser.bucketName, sourceObject.Key) reader, length, md5hex, err := sourceClnt.Get(sourceURLParser.bucketName, sourceObject.Key)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Errorln(err) console.Errorf("mc: unable to read source: %s\n", err)
} }
writeCloser, err := getRecursiveTargetWriter(targetURLParser, sourceObject.Key, md5hex, length) writeCloser, err := getRecursiveTargetWriter(targetURLParser, sourceObject.Key, md5hex, length)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Errorln(err) console.Errorf("mc: unable to read target: %s\n", err)
} }
var writers []io.Writer var writers []io.Writer
writers = append(writers, writeCloser) writers = append(writers, writeCloser)
@@ -107,14 +107,14 @@ func doCopyCmdRecursive(ctx *cli.Context) {
_, err = io.CopyN(multiWriter, reader, length) _, err = io.CopyN(multiWriter, reader, length)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Errorln("Unable to write to target") console.Errorln("mc: Unable to write to target")
} }
// close writers // close writers
err = writeCloser.Close() err = writeCloser.Close()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Errorln("Unable to close writer, object may not of written properly.") console.Errorln("mc: Unable to close writer, object may not of written properly.")
} }
} }
return return

View File

@@ -54,28 +54,28 @@ func doUpdateCmd(ctx *cli.Context) {
req, err := getReq(mcUpdateURL) req, err := getReq(mcUpdateURL)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to update:", mcUpdateURL) console.Fatalln("mc: Unable to update:", mcUpdateURL)
} }
res, err := http.DefaultTransport.RoundTrip(req) res, err := http.DefaultTransport.RoundTrip(req)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to retrieve:", mcUpdateURL) console.Fatalln("mc: Unable to retrieve:", mcUpdateURL)
} }
if res.StatusCode != http.StatusOK { if res.StatusCode != http.StatusOK {
msg := fmt.Sprint("Received invalid HTTP status: ", res.StatusCode) msg := fmt.Sprint("Received invalid HTTP status: ", res.StatusCode)
log.Debug.Println(iodine.New(errors.New(msg), nil)) log.Debug.Println(iodine.New(errors.New(msg), nil))
console.Fatalln(msg) console.Fatalln("mc: " + msg)
} }
ures := updateResults{} ures := updateResults{}
err = json.NewDecoder(res.Body).Decode(&ures) err = json.NewDecoder(res.Body).Decode(&ures)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to parse JSON:", mcUpdateURL) console.Fatalln("mc: Unable to parse JSON:", mcUpdateURL)
} }
latest, err := time.Parse(time.RFC3339Nano, ures.LatestBuild) latest, err := time.Parse(time.RFC3339Nano, ures.LatestBuild)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to parse update time:", ures.LatestBuild) console.Fatalln("mc: Unable to parse update time:", ures.LatestBuild)
} }
if latest.After(ctx.App.Compiled) { if latest.After(ctx.App.Compiled) {
// FIXME : find some proper versioning scheme here // FIXME : find some proper versioning scheme here

View File

@@ -18,6 +18,14 @@ package main
import "fmt" import "fmt"
type errInvalidTheme struct {
theme string
}
func (e errInvalidTheme) Error() string {
return "invalid theme: " + e.theme
}
type errInvalidArgument struct{} type errInvalidArgument struct{}
func (e errInvalidArgument) Error() string { func (e errInvalidArgument) Error() string {

10
main.go
View File

@@ -37,7 +37,7 @@ func checkConfig() {
_, err := user.Current() _, err := user.Current()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalln("Unable to obtain user's home directory") console.Fatalln("mc: Unable to obtain user's home directory")
} }
if !isMcConfigExist() { if !isMcConfigExist() {
@@ -49,13 +49,13 @@ func checkConfig() {
config, err := getMcConfig() config, err := getMcConfig()
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("Unable to read config file: %s\n", mustGetMcConfigPath()) console.Fatalf("mc: Unable to read config file: %s\n", mustGetMcConfigPath())
} }
err = checkMcConfig(config) err = checkMcConfig(config)
if err != nil { if err != nil {
log.Debug.Println(iodine.New(err, nil)) log.Debug.Println(iodine.New(err, nil))
console.Fatalf("Error in config file: %s\n", mustGetMcConfigPath()) console.Fatalf("mc: Error in config file: %s\n", mustGetMcConfigPath())
} }
} }
@@ -106,7 +106,7 @@ func main() {
if theme != "" { if theme != "" {
err := console.SetTheme(theme) err := console.SetTheme(theme)
if err != nil { if err != nil {
console.Fatalf("Unable to set theme [%s]\n", theme) console.Fatalf("mc: Unable to set theme [%s]\n", theme)
} }
} }
checkConfig() checkConfig()
@@ -114,7 +114,7 @@ func main() {
} }
app.After = func(ctx *cli.Context) error { app.After = func(ctx *cli.Context) error {
if !isMcConfigExist() && ctx.Command.Name != "config" { if !isMcConfigExist() && ctx.Command.Name != "config" {
console.Fatalln("Error: mc is not configured. Please run \"mc config\".") console.Fatalln("mc: error ``mc`` is not configured. Please run \"mc config\".")
} }
return nil return nil

View File

@@ -23,6 +23,7 @@ import (
"sync" "sync"
"github.com/fatih/color" "github.com/fatih/color"
"github.com/minio-io/minio/pkg/iodine"
) )
var ( var (
@@ -101,7 +102,8 @@ func isValidTheme(themeName string) bool {
// SetTheme sets a color theme // SetTheme sets a color theme
func SetTheme(themeName string) error { func SetTheme(themeName string) error {
if !isValidTheme(themeName) { if !isValidTheme(themeName) {
return errors.New("Invalid theme") msg := fmt.Sprintf("invalid theme: %s", themeName)
return iodine.New(errors.New(msg), nil)
} }
currentTheme = themeName currentTheme = themeName
mutex.Lock() mutex.Lock()