From 30964f0ae14ca4c27b852007a9dbaba3c66ea393 Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Tue, 23 Oct 2018 17:57:47 +0800 Subject: [PATCH 1/2] add some function to adjust juju/error --- juju_adaptor.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/juju_adaptor.go b/juju_adaptor.go index 0b20f57..ccfb2fc 100644 --- a/juju_adaptor.go +++ b/juju_adaptor.go @@ -2,6 +2,7 @@ package errors import ( "fmt" + "strings" ) // ==================== juju adaptor start ======================== @@ -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...) @@ -76,4 +82,18 @@ 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...) +} + +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 ======================== From c22a95629595d66d2902c19514ad2e68147bcb9b Mon Sep 17 00:00:00 2001 From: WangXiangUSTC <347249478@qq.com> Date: Tue, 23 Oct 2018 18:00:01 +0800 Subject: [PATCH 2/2] add comment --- juju_adaptor.go | 1 + 1 file changed, 1 insertion(+) diff --git a/juju_adaptor.go b/juju_adaptor.go index ccfb2fc..8bcfe2f 100644 --- a/juju_adaptor.go +++ b/juju_adaptor.go @@ -87,6 +87,7 @@ 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") }