Files
sqlite3/error.go

55 lines
1.1 KiB
Go
Raw Normal View History

2023-01-12 13:43:35 +00:00
package sqlite3
import (
2023-02-07 03:11:59 +00:00
"runtime"
2023-01-12 13:43:35 +00:00
"strconv"
"strings"
)
type Error struct {
2023-01-16 12:54:24 +00:00
Code ErrorCode
ExtendedCode ExtendedErrorCode
2023-01-12 13:43:35 +00:00
str string
msg string
}
2023-01-21 00:33:46 +00:00
func (e *Error) Error() string {
2023-01-12 13:43:35 +00:00
var b strings.Builder
b.WriteString("sqlite3: ")
if e.str != "" {
b.WriteString(e.str)
} else {
2023-01-16 12:54:24 +00:00
b.WriteString(strconv.Itoa(int(e.Code)))
2023-01-12 13:43:35 +00:00
}
if e.msg != "" {
b.WriteByte(':')
b.WriteByte(' ')
b.WriteString(e.msg)
}
return b.String()
}
2023-01-19 14:31:32 +00:00
type errorString string
func (e errorString) Error() string { return string(e) }
const (
2023-01-25 14:59:02 +00:00
nilErr = errorString("sqlite3: invalid memory address or null pointer dereference")
2023-01-19 14:31:32 +00:00
oomErr = errorString("sqlite3: out of memory")
rangeErr = errorString("sqlite3: index out of range")
noNulErr = errorString("sqlite3: missing NUL terminator")
noGlobalErr = errorString("sqlite3: could not find global: ")
noFuncErr = errorString("sqlite3: could not find function: ")
)
2023-02-07 03:11:59 +00:00
func assertErr() errorString {
msg := "sqlite3: assertion failed"
if _, file, line, ok := runtime.Caller(1); ok {
msg += " (" + file + ":" + strconv.Itoa(line) + ")"
}
return errorString(msg)
}