func PanicIfErrIndexOutOfBounds(what string, index int, length int) { if index < 0 || index >= length { if Config.FormatWithCallStack { what += debug.CallStackInfo(2) } panic(&ErrIndexOutOfBounds{what, index, length}) } }
func IfErrIndexOutOfBounds(what string, index int, length int) *ErrIndexOutOfBounds { if index < 0 || index >= length { if Config.FormatWithCallStack { what += debug.CallStackInfo(2) } return &ErrIndexOutOfBounds{what, index, length} } return nil }
// FormatSkipStackFrames formats an error with call stack information if FormatWithCallStack is true. // It skips skip stack frames. func FormatSkipStackFrames(skip int, format string, args ...interface{}) error { if Config.FormatWithCallStack { format += "\n" + debug.CallStackInfo(skip+1) } return fmt.Errorf(format, args...) }