Skip to content

Commit

Permalink
Merge pull request #11 from WangXiangUSTC/xiang/add_new_error
Browse files Browse the repository at this point in the history
add some function to adjust juju/error
  • Loading branch information
gregwebs authored Oct 24, 2018
2 parents 31ffda8 + c22a956 commit 1176802
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions juju_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package errors

import (
"fmt"
"strings"
)

// ==================== juju adaptor start ========================
Expand Down Expand Up @@ -61,6 +62,11 @@ func ErrorStack(err error) string {
return fmt.Sprintf("%+v", err)
}

// IsNotFound reports whether err was not found error.
func IsNotFound(err error) bool {
return strings.Contains(err.Error(), "not found")
}

// NotFoundf represents an error with not found message.
func NotFoundf(format string, args ...interface{}) error {
return Errorf(format+" not found", args...)
Expand All @@ -76,4 +82,19 @@ func NotSupportedf(format string, args ...interface{}) error {
return Errorf(format+" not supported", args...)
}

// NotValidf represents an error with not valid message.
func NotValidf(format string, args ...interface{}) error {
return Errorf(format+" not valid", args...)
}

// IsAlreadyExists reports whether err was already exists error.
func IsAlreadyExists(err error) bool {
return strings.Contains(err.Error(), "already exists")
}

// AlreadyExistsf represents an error with already exists message.
func AlreadyExistsf(format string, args ...interface{}) error {
return Errorf(format+" already exists", args...)
}

// ==================== juju adaptor end ========================

0 comments on commit 1176802

Please sign in to comment.