Move from Fatal/Error to fatalIf/errorIf

This commit is contained in:
Harshavardhana
2015-08-09 22:41:49 -07:00
parent f1589263e7
commit ae2a20dffc
18 changed files with 63 additions and 63 deletions
+3 -3
View File
@@ -64,14 +64,14 @@ func runAccessCmd(ctx *cli.Context) {
config := mustGetMcConfig()
acl := bucketACL(ctx.Args().First())
if !acl.isValidBucketACL() {
Fatal(probe.NewError(errInvalidACL{acl: acl.String()}))
fatalIf(probe.NewError(errInvalidACL{acl: acl.String()}))
}
for _, arg := range ctx.Args().Tail() {
targetURL, err := getExpandedURL(arg, config.Aliases)
Fatal(err)
fatalIf(err)
err = doUpdateAccessCmd(targetURL, acl)
Fatal(err)
fatalIf(err)
}
}
+2 -2
View File
@@ -70,11 +70,11 @@ func mainCat(ctx *cli.Context) {
}
if stdinMode {
Fatal(catOut(os.Stdin))
fatalIf(catOut(os.Stdin))
} else {
// Convert arguments to URLs: expand alias, fix format...
for _, arg := range ctx.Args() {
Fatal(catURL(arg))
fatalIf(catURL(arg))
}
}
+1 -1
View File
@@ -67,7 +67,7 @@ func runConfigCmd(ctx *cli.Context) {
console.Fatalf("Incorrect number of arguments, please read \"mc config help\". %s", errInvalidArgument{})
}
msg, err := doConfig(arg, tailArgs)
Fatal(err)
fatalIf(err)
console.Infoln(msg)
}
+8 -8
View File
@@ -66,7 +66,7 @@ func getMcConfigDir() (string, *probe.Error) {
// mustGetMcConfigDir - construct minio client config folder or fail
func mustGetMcConfigDir() (configDir string) {
configDir, err := getMcConfigDir()
Fatal(err)
fatalIf(err)
return configDir
}
@@ -94,7 +94,7 @@ func getMcConfigPath() (string, *probe.Error) {
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
func mustGetMcConfigPath() string {
path, err := getMcConfigPath()
Fatal(err)
fatalIf(err)
return path
}
@@ -132,7 +132,7 @@ func getMcConfig() (*configV1, *probe.Error) {
// mustGetMcConfig - reads configuration file and returns configs, exits on error
func mustGetMcConfig() *configV1 {
config, err := getMcConfig()
Fatal(err)
fatalIf(err)
return config
}
@@ -175,9 +175,9 @@ func migrateConfigV1ToV101() {
}
conf := newConfigV1()
config, err := quick.New(conf)
Fatal(err)
fatalIf(err)
err = config.Load(mustGetMcConfigPath())
Fatal(err)
fatalIf(err)
conf = config.Data().(*configV1)
// version is the same return
@@ -206,9 +206,9 @@ func migrateConfigV1ToV101() {
{
newConfig, err := quick.New(conf)
Fatal(err)
fatalIf(err)
err = newConfig.Save(mustGetMcConfigPath())
Fatal(err)
fatalIf(err)
}
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), mcPreviousConfigVersion, mcCurrentConfigVersion)
@@ -286,6 +286,6 @@ func newConfig() (config quick.Config, err *probe.Error) {
// mustNewConfig instantiates a new config handler, exists upon error
func mustNewConfig() quick.Config {
config, err := newConfig()
Fatal(err)
fatalIf(err)
return config
}
+2 -2
View File
@@ -154,7 +154,7 @@ func doPrepareCopyURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if cpURLs.Error != nil {
Error(cpURLs.Error)
errorIf(cpURLs.Error)
break
}
@@ -221,7 +221,7 @@ func doCopyCmdSession(session *sessionV2) {
session.Header.LastCopied = cpURLs.SourceContent.Name
} else {
console.Println()
Error(cpURLs.Error)
errorIf(cpURLs.Error)
}
case <-trapCh: // Receive interrupt notification.
session.Close()
+13 -13
View File
@@ -108,12 +108,12 @@ func checkCopySyntaxTypeA(srcURLs []string, tgtURL string) {
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
}
}
@@ -124,19 +124,19 @@ func checkCopySyntaxTypeB(srcURLs []string, tgtURL string) {
}
srcURL := srcURLs[0]
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
}
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
}
}
}
@@ -149,16 +149,16 @@ func checkCopySyntaxTypeC(srcURLs []string, tgtURL string) {
srcURL := srcURLs[0]
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
}
_, tgtContent, err := url2Stat(tgtURL)
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
}
}
}
@@ -169,18 +169,18 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
if isURLRecursive(srcURL) {
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if !srcContent.Type.IsDir() { // Ellipses is supported only for folders.
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
}
} else { // Regular URL.
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if srcContent.Type.IsDir() {
console.Fatalf("Source ‘%s’ is a folder. Use ‘%s...’ argument to copy this folder and its contents recursively. %s\n", srcURL, srcURL, errInvalidArgument{})
}
if !srcContent.Type.IsRegular() {
Fatal(probe.NewError(errSourceIsNotFile{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotFile{URL: srcURL}))
}
}
}
@@ -188,7 +188,7 @@ func checkCopySyntaxTypeD(srcURLs []string, tgtURL string) {
// Target exist?.
if err == nil {
if !tgtContent.Type.IsDir() {
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
}
}
}
+3 -3
View File
@@ -63,15 +63,15 @@ func runDiffCmd(ctx *cli.Context) {
var err *probe.Error
firstURL, err = getExpandedURL(firstURL, config.Aliases)
Fatal(err)
fatalIf(err)
secondURL, err = getExpandedURL(secondURL, config.Aliases)
Fatal(err)
fatalIf(err)
if isURLRecursive(secondURL) {
console.Fatalf("Second URL cannot be recursive. %s\n", errInvalidArgument{})
}
newFirstURL := stripRecursiveURL(firstURL)
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
Fatal(diff.err)
fatalIf(diff.err)
console.PrintC(diff.message)
}
console.Println()
+4 -4
View File
@@ -21,8 +21,8 @@ import (
"github.com/minio/mc/pkg/probe"
)
// Fatal wrapper function which takes error and selectively prints stack frames if available on debug
func Fatal(err *probe.Error) {
// fatalIf wrapper function which takes error and selectively prints stack frames if available on debug
func fatalIf(err *probe.Error) {
if err == nil {
return
}
@@ -32,8 +32,8 @@ func Fatal(err *probe.Error) {
console.Fatalln(err)
}
// Error synonymous with Fatal but doesn't exit on error != nil
func Error(err *probe.Error) {
// errorIf synonymous with fatalIf but doesn't exit on error != nil
func errorIf(err *probe.Error) {
if err == nil {
return
}
+3 -3
View File
@@ -111,14 +111,14 @@ func firstTimeRun() {
console.Fatalf("Unable to create ‘mc’ config folder. %s\n", err)
}
config, err := newConfig()
Fatal(err)
fatalIf(err)
err = writeConfig(config)
Fatal(err)
fatalIf(err)
console.Infoln("Configuration written to [" + mustGetMcConfigPath() + "]. Please update your access credentials.")
}
if !isSessionDirExists() {
err := createSessionDir()
Fatal(err)
fatalIf(err)
}
checkGolangVersion()
}
+2 -2
View File
@@ -83,10 +83,10 @@ func runListCmd(ctx *cli.Context) {
config := mustGetMcConfig()
for _, arg := range args {
targetURL, err := getExpandedURL(arg, config.Aliases)
Fatal(err)
fatalIf(err)
// if recursive strip off the "..."
newTargetURL := stripRecursiveURL(targetURL)
Fatal(doListCmd(newTargetURL, isURLRecursive(targetURL)))
fatalIf(doListCmd(newTargetURL, isURLRecursive(targetURL)))
}
}
+2 -2
View File
@@ -79,11 +79,11 @@ func doList(clnt client.Client, recursive bool) *probe.Error {
switch contentCh.Err.ToError().(type) {
// handle this specifically for filesystem
case client.ISBrokenSymlink:
Error(contentCh.Err)
errorIf(contentCh.Err)
continue
}
if os.IsNotExist(contentCh.Err.ToError()) || os.IsPermission(contentCh.Err.ToError()) {
Error(contentCh.Err)
errorIf(contentCh.Err)
continue
}
err = contentCh.Err
+2 -2
View File
@@ -38,7 +38,7 @@ func checkConfig() {
// Ensures config file is sane
{
_, err := getMcConfig()
Fatal(err)
fatalIf(err)
}
}
@@ -90,7 +90,7 @@ func registerBefore(ctx *cli.Context) error {
}
if err := console.SetTheme(themeName); err != nil {
console.Errorf("Failed to set theme ‘%s’.", themeName)
Error(err)
errorIf(err)
}
// Migrate any old version of config / state files to newer format.
+2 -2
View File
@@ -60,10 +60,10 @@ func runMakeBucketCmd(ctx *cli.Context) {
config := mustGetMcConfig()
for _, arg := range ctx.Args() {
targetURL, err := getExpandedURL(arg, config.Aliases)
Fatal(err)
fatalIf(err)
err = doMakeBucketCmd(targetURL)
Fatal(err)
fatalIf(err)
console.Infoln("Bucket created successfully : " + targetURL)
}
}
+2 -2
View File
@@ -152,7 +152,7 @@ func doPrepareMirrorURLs(session *sessionV2, trapCh <-chan bool) {
break
}
if sURLs.Error != nil {
Error(sURLs.Error)
errorIf(sURLs.Error)
break
}
if sURLs.isEmpty() {
@@ -221,7 +221,7 @@ func doMirrorCmdSession(session *sessionV2) {
session.Header.LastCopied = sURLs.SourceContent.Name
} else {
console.Println()
Error(sURLs.Error)
errorIf(sURLs.Error)
}
case <-trapCh: // Receive interrupt notification.
session.Close()
+5 -5
View File
@@ -57,7 +57,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
// extract URLs.
URLs, err := args2URLs(ctx.Args())
Fatal(err)
fatalIf(err)
srcURL := URLs[0]
tgtURLs := URLs[1:]
@@ -66,7 +66,7 @@ func checkMirrorSyntax(ctx *cli.Context) {
// Source cannot be a folder (except when recursive)
if !isURLRecursive(srcURL) {
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if !srcContent.Type.IsRegular() {
if srcContent.Type.IsDir() {
@@ -93,16 +93,16 @@ func checkMirrorSyntax(ctx *cli.Context) {
}
srcURL = stripRecursiveURL(srcURL)
_, srcContent, err := url2Stat(srcURL)
Fatal(err)
fatalIf(err)
if srcContent.Type.IsRegular() { // Ellipses is supported only for folders.
Fatal(probe.NewError(errSourceIsNotDir{URL: srcURL}))
fatalIf(probe.NewError(errSourceIsNotDir{URL: srcURL}))
}
for _, tgtURL := range tgtURLs {
_, content, err := url2Stat(tgtURL)
if err == nil {
if !content.Type.IsDir() {
Fatal(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
fatalIf(probe.NewError(errTargetIsNotDir{URL: tgtURL}))
}
}
}
+5 -5
View File
@@ -85,7 +85,7 @@ func clearSession(sid string) {
if sid == "all" {
for _, sid := range getSessionIDs() {
session, err := loadSessionV2(sid)
Fatal(err)
fatalIf(err)
session.Delete()
}
return
@@ -96,7 +96,7 @@ func clearSession(sid string) {
}
session, err := loadSessionV2(sid)
Fatal(err)
fatalIf(err)
if session != nil {
session.Delete()
}
@@ -119,13 +119,13 @@ func runSessionCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
}
if !isSessionDirExists() {
Fatal(createSessionDir())
fatalIf(createSessionDir())
}
switch strings.TrimSpace(ctx.Args().First()) {
// list resumable sessions
case "list":
err := listSessions()
Fatal(err)
fatalIf(err)
case "resume":
if len(ctx.Args().Tail()) != 1 {
cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code
@@ -140,7 +140,7 @@ func runSessionCmd(ctx *cli.Context) {
console.Fatalln(errInvalidSessionID{id: sid})
}
s, err := loadSessionV2(sid)
Fatal(err)
fatalIf(err)
// extra check for testing purposes
if s == nil {
return
+3 -3
View File
@@ -71,13 +71,13 @@ func runShareCmd(ctx *cli.Context) {
if len(args) == 2 {
var err error
expires, err = time.ParseDuration(args.Last())
Fatal(probe.NewError(err))
fatalIf(probe.NewError(err))
}
targetURL, err := getExpandedURL(url, config.Aliases)
Fatal(err)
fatalIf(err)
// if recursive strip off the "..."
newTargetURL := stripRecursiveURL(targetURL)
Fatal(doShareCmd(newTargetURL, isURLRecursive(targetURL), expires))
fatalIf(doShareCmd(newTargetURL, isURLRecursive(targetURL), expires))
}
func getNewTargetURL(targetParser *client.URL, name string) string {
+1 -1
View File
@@ -104,7 +104,7 @@ func runUpdateCmd(ctx *cli.Context) {
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
}
msg, err := doUpdateCheck()
Fatal(err)
fatalIf(err)
// no msg do not print one
if msg != "" {
console.Infoln(msg)