github.com/tencent/goom@v1.0.1/erro/illegal_param.go (about) 1 package erro 2 3 // IllegalParam 参数错误异常 4 type IllegalParam struct { 5 cause error 6 paramName string 7 paramValue string 8 funcName string 9 } 10 11 // Error 返回错误字符串 12 func (i *IllegalParam) Error() (s string) { 13 defer func() { 14 if i.cause != nil { 15 s = s + "\ncause: " + i.cause.Error() 16 } 17 }() 18 if len(i.funcName) > 0 { 19 return "Illegal param error when call" + i.funcName + ", param=" + i.paramName + ", value=" + i.paramValue 20 } 21 return "Illegal param error, param=" + i.paramName + ", value=" + i.paramValue 22 } 23 24 // Cause 获取错误的原因 25 func (i *IllegalParam) Cause() error { 26 return i.cause 27 } 28 29 // NewIllegalParamError 创建参数异常 30 // paramName 参数名 31 // paramValue 参数值 32 func NewIllegalParamError(paramName string, paramValue string) error { 33 return &IllegalParam{paramName: paramName, paramValue: paramValue} 34 } 35 36 // NewIllegalParamCError 创建参数异常 37 // paramName 参数名 38 // paramValue 参数值 39 func NewIllegalParamCError(paramName string, paramValue string, cause error) error { 40 return &IllegalParam{paramName: paramName, paramValue: paramValue, cause: cause} 41 } 42 43 // NewIllegalCallError 创建参数异常 44 // funcName 函数名 45 // paramName 参数名 46 // paramValue 参数值 47 func NewIllegalCallError(funcName string, paramName string, paramValue string) error { 48 return &IllegalParam{funcName: funcName, paramName: paramName, paramValue: paramValue} 49 }