本文整理汇总了Golang中github.com/juju/errgo.Cause函数的典型用法代码示例。如果您正苦于以下问题:Golang Cause函数的具体用法?Golang Cause怎么用?Golang Cause使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Cause函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestCause
func (*errorsSuite) TestCause(c *gc.C) {
c.Assert(errgo.Cause(someErr), gc.Equals, someErr)
causeErr := errgo.New("cause error")
underlyingErr := errgo.New("underlying error") //err TestCause#1
err := errgo.WithCausef(underlyingErr, causeErr, "foo %d", 99) //err TestCause#2
c.Assert(errgo.Cause(err), gc.Equals, causeErr)
checkErr(c, err, underlyingErr, "foo 99: underlying error", "[{$TestCause#2$: foo 99} {$TestCause#1$: underlying error}]", causeErr)
err = &embed{err.(*errgo.Err)}
c.Assert(errgo.Cause(err), gc.Equals, causeErr)
}
开发者ID:vnadgir-ef,项目名称:fleet-ui,代码行数:13,代码来源:errors_test.go
示例2: GetSessionID
func (a *annactl) GetSessionID() (string, error) {
a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call GetSession")
// Read session ID.
raw, err := a.Service().FS().ReadFile(SessionFilePath)
if _, ok := errgo.Cause(err).(*os.PathError); ok {
// Session file does not exist. Go ahead to create one.
} else if err != nil {
return "", maskAny(err)
}
if len(raw) != 0 {
return string(raw), nil
}
// Create session ID.
newSessionID, err := a.Service().ID().New()
if err != nil {
return "", maskAny(err)
}
err = a.Service().FS().WriteFile(SessionFilePath, []byte(newSessionID), os.FileMode(0644))
if err != nil {
return "", maskAny(err)
}
return string(newSessionID), nil
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:27,代码来源:common.go
示例3: IsUnsupportedType
// IsUnsupportedType asserts json.UnsupportedTypeError.
func IsUnsupportedType(err error) bool {
if _, ok := errgo.Cause(err).(*json.UnsupportedTypeError); ok {
return true
}
return false
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:8,代码来源:error.go
示例4: TestCause
func TestCause(t *testing.T) {
if cause := errgo.Cause(someErr); cause != someErr {
t.Fatalf("expected %q kind; got %#v", someErr, cause)
}
causeErr := errgo.New("cause error")
underlyingErr := errgo.New("underlying error") //err TestCause#1
err := errgo.WithCausef(underlyingErr, causeErr, "foo %d", 99) //err TestCause#2
if errgo.Cause(err) != causeErr {
t.Fatalf("expected %q; got %#v", causeErr, errgo.Cause(err))
}
checkErr(t, err, underlyingErr, "foo 99: underlying error", "[{$TestCause#2$: foo 99} {$TestCause#1$: underlying error}]", causeErr)
err = &embed{err.(*errgo.Err)}
if errgo.Cause(err) != causeErr {
t.Fatalf("expected %q; got %#v", causeErr, errgo.Cause(err))
}
}
开发者ID:howbazaar,项目名称:errgo,代码行数:16,代码来源:errors_test.go
示例5: maskAnyf
func maskAnyf(err error, f string, v ...interface{}) error {
if err == nil {
return nil
}
f = fmt.Sprintf("%s: %s", err.Error(), f)
newErr := errgo.WithCausef(nil, errgo.Cause(err), f, v...)
newErr.(*errgo.Err).SetLocation(1)
return newErr
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:11,代码来源:error.go
示例6: IsParseFloatSyntax
// IsParseFloatSyntax asserts strconv.ErrSyntax.
func IsParseFloatSyntax(err error) bool {
cause := errgo.Cause(err)
if e, ok := cause.(*strconv.NumError); ok {
if e.Err == strconv.ErrSyntax {
return true
}
}
return false
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:12,代码来源:calculate_error.go
示例7: checkErr
func checkErr(c *gc.C, err, underlying error, msg string, details string, cause error) {
c.Assert(err, gc.NotNil)
c.Assert(err.Error(), gc.Equals, msg)
if err, ok := err.(errgo.Wrapper); ok {
c.Assert(err.Underlying(), gc.Equals, underlying)
} else {
c.Assert(underlying, gc.IsNil)
}
c.Assert(errgo.Cause(err), gc.Equals, cause)
wantDetails := replaceLocations(details)
c.Assert(errgo.Details(err), gc.Equals, wantDetails)
}
开发者ID:vnadgir-ef,项目名称:fleet-ui,代码行数:12,代码来源:errors_test.go
示例8: checkErr
func checkErr(t *testing.T, err, underlying error, msg string, details string, cause error) {
if err == nil {
t.Fatalf("err is nil; want %q", msg)
}
if err.Error() != msg {
t.Fatalf("unexpected message: want %q; got %q", msg, err.Error())
}
if err, ok := err.(errgo.Wrapper); ok {
if err.Underlying() != underlying {
t.Fatalf("unexpected underlying error: want %q; got %v", underlying, err.Underlying())
}
} else if underlying != nil {
t.Fatalf("no underlying error found; want %q", underlying)
}
if errgo.Cause(err) != cause {
t.Fatalf("unexpected cause: want %#v; got %#v", cause, errgo.Cause(err))
}
wantDetails := replaceLocations(details)
if gotDetails := errgo.Details(err); gotDetails != wantDetails {
t.Fatalf("unexpected details: want %q; got %q", wantDetails, gotDetails)
}
}
开发者ID:howbazaar,项目名称:errgo,代码行数:22,代码来源:errors_test.go
示例9: getRegistration
// getRegistration reads the registration resource for the registration path.
// If no such file exists, nil is returned.
func (s *acmeService) getRegistration() (*acme.RegistrationResource, error) {
raw, err := ioutil.ReadFile(s.RegistrationPath)
if err != nil {
if os.IsNotExist(errgo.Cause(err)) {
return nil, nil
}
return nil, maskAny(err)
}
res := &acme.RegistrationResource{}
if err := json.Unmarshal(raw, res); err != nil {
return nil, maskAny(err)
}
return res, nil
}
开发者ID:pulcy,项目名称:robin,代码行数:18,代码来源:storage.go
示例10: NewErrorResponseFromError
// NewErrorResponseFromError creates an ErrorResponse from the given error.
// This ErrorResponse can be sent directly to an HttpResponseWriter.
func NewErrorResponseFromError(err error) ErrorResponse {
var er *ErrorResponse
if erX, ok := err.(*ErrorResponse); ok {
er = erX
} else if erX, ok := errgo.Cause(err).(*ErrorResponse); ok {
er = erX
msg := err.Error()
if msg != "" {
er.TheError.Message = msg
}
} else {
er = &ErrorResponse{}
er.TheError.Message = err.Error()
er.TheError.Code = -1
}
return *er
}
开发者ID:pulcy,项目名称:rest-kit,代码行数:20,代码来源:errors.go
示例11: getPrivateKey
// getPrivateKey loads the private key from the private key path.
// If there is no such file, a new private key is generated.
func (s *acmeService) getPrivateKey() (*rsa.PrivateKey, error) {
key, err := loadRSAPrivateKey(s.PrivateKeyPath)
if err == nil {
return key, nil
} else if !os.IsNotExist(errgo.Cause(err)) {
return nil, maskAny(err)
}
// private key not found, generate one
key, err = rsa.GenerateKey(rand.Reader, s.KeyBits)
if err != nil {
return nil, maskAny(err)
}
if err := saveRSAPrivateKey(key, s.PrivateKeyPath); err != nil {
return nil, maskAny(err)
}
return key, nil
}
开发者ID:pulcy,项目名称:robin,代码行数:22,代码来源:storage.go
示例12: IsInvalidCLGTreeID
// IsInvalidCLGTreeID asserts invalidCLGTreeIDError.
func IsInvalidCLGTreeID(err error) bool {
return errgo.Cause(err) == invalidCLGTreeIDError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例13: IsInvalidStorageFlag
// IsInvalidStorageFlag asserts invalidStorageFlagError.
func IsInvalidStorageFlag(err error) bool {
return errgo.Cause(err) == invalidStorageFlagError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例14: IsNotMaster
func IsNotMaster(err error) bool {
return errgo.Cause(err) == NotMasterError
}
开发者ID:pulcy,项目名称:robin,代码行数:3,代码来源:error.go
示例15: IsInvalidPosition
// IsInvalidPosition asserts invalidPositionError.
func IsInvalidPosition(err error) bool {
return errgo.Cause(err) == invalidPositionError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例16: IsInvalidNetworkPayload
// IsInvalidNetworkPayload asserts invalidNetworkPayloadError.
func IsInvalidNetworkPayload(err error) bool {
return errgo.Cause(err) == invalidNetworkPayloadError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例17: IsWorkerCanceled
// IsWorkerCanceled asserts workerCanceledError.
func IsWorkerCanceled(err error) bool {
return errgo.Cause(err) == workerCanceledError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例18: IsCannotParse
// IsCannotParse asserts cannotParseError.
func IsCannotParse(err error) bool {
return errgo.Cause(err) == cannotParseError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例19: IsInvalidInformationID
// IsInvalidInformationID asserts invalidInformationIDError.
func IsInvalidInformationID(err error) bool {
return errgo.Cause(err) == invalidInformationIDError
}
开发者ID:xh3b4sd,项目名称:anna,代码行数:4,代码来源:error.go
示例20: IsJobDependency
// IsJobDependency returns true if the given err is a JobDependencyError.
func IsJobDependency(err error) bool {
return errgo.Cause(err) == JobDependencyError
}
开发者ID:giantswarm,项目名称:yochu,代码行数:4,代码来源:error.go
注:本文中的github.com/juju/errgo.Cause函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论