github.com/Finschia/finschia-sdk@v0.48.1/types/errors/doc.go (about) 1 /* 2 Package errors implements custom error interfaces for cosmos-sdk. 3 4 Error declarations should be generic and cover broad range of cases. Each 5 returned error instance can wrap a generic error declaration to provide more 6 details. 7 8 This package provides a broad range of errors declared that fits all common 9 cases. If an error is very specific for an extension it can be registered outside 10 of the errors package. If it will be needed my many extensions, please consider 11 registering it in the errors package. To create a new error instance use Register 12 function. You must provide a unique, non zero error code and a short description, for example: 13 14 var ErrZeroDivision = errors.Register(9241, "zero division") 15 16 When returning an error, you can attach to it an additional context 17 information by using Wrap function, for example: 18 19 func safeDiv(val, div int) (int, err) { 20 if div == 0 { 21 return 0, errors.Wrapf(ErrZeroDivision, "cannot divide %d", val) 22 } 23 return val / div, nil 24 } 25 26 The first time an error instance is wrapped a stacktrace is attached as well. 27 Stacktrace information can be printed using %+v and %v formats. 28 29 %s is just the error message 30 %+v is the full stack trace 31 %v appends a compressed [filename:line] where the error was created 32 */ 33 package errors