7 "github.com/ncruces/go-sqlite3/internal/util"
10// Error wraps an SQLite Error Code.
12// https://sqlite.org/c3ref/errcode.html
19// Code returns the primary error code for this error.
21// https://sqlite.org/rescode.html
22func (e *Error) Code() ErrorCode {
23 return ErrorCode(e.code)
26// ExtendedCode returns the extended error code for this error.
28// https://sqlite.org/rescode.html
29func (e *Error) ExtendedCode() ExtendedErrorCode {
30 return xErrorCode(e.code)
33// Error implements the error interface.
34func (e *Error) Error() string {
36 b.WriteString(util.ErrorCodeString(uint32(e.code)))
46// Is tests whether this error matches a given [ErrorCode] or [ExtendedErrorCode].
48// It makes it possible to do:
50// if errors.Is(err, sqlite3.BUSY) {
53func (e *Error) Is(err error) bool {
54 switch c := err.(type) {
57 case ExtendedErrorCode:
58 return c == e.ExtendedCode()
63// As converts this error to an [ErrorCode] or [ExtendedErrorCode].
64func (e *Error) As(err any) bool {
65 switch c := err.(type) {
69 case *ExtendedErrorCode:
76// Temporary returns true for [BUSY] errors.
77func (e *Error) Temporary() bool {
78 return e.Code() == BUSY
81// Timeout returns true for [BUSY_TIMEOUT] errors.
82func (e *Error) Timeout() bool {
83 return e.ExtendedCode() == BUSY_TIMEOUT
86// SQL returns the SQL starting at the token that triggered a syntax error.
87func (e *Error) SQL() string {
91// Error implements the error interface.
92func (e ErrorCode) Error() string {
93 return util.ErrorCodeString(uint32(e))
96// Temporary returns true for [BUSY] errors.
97func (e ErrorCode) Temporary() bool {
98 return e == BUSY || e == INTERRUPT
101// ExtendedCode returns the extended error code for this error.
102func (e ErrorCode) ExtendedCode() ExtendedErrorCode {
106// Error implements the error interface.
107func (e ExtendedErrorCode) Error() string {
108 return util.ErrorCodeString(uint32(e))
111// Is tests whether this error matches a given [ErrorCode].
112func (e ExtendedErrorCode) Is(err error) bool {
113 c, ok := err.(ErrorCode)
114 return ok && c == ErrorCode(e)
117// As converts this error to an [ErrorCode].
118func (e ExtendedErrorCode) As(err any) bool {
119 c, ok := err.(*ErrorCode)
126// Temporary returns true for [BUSY] errors.
127func (e ExtendedErrorCode) Temporary() bool {
128 return ErrorCode(e) == BUSY || ErrorCode(e) == INTERRUPT
131// Timeout returns true for [BUSY_TIMEOUT] errors.
132func (e ExtendedErrorCode) Timeout() bool {
133 return e == BUSY_TIMEOUT
136// Code returns the primary error code for this error.
137func (e ExtendedErrorCode) Code() ErrorCode {
141func errorCode(err error, def ErrorCode) (msg string, code res_t) {
142 switch code := err.(type) {
146 return "", res_t(code)
148 return "", res_t(code)
150 return code.msg, res_t(code.code)
156 case errors.As(err, &xcode):
158 case errors.As(err, &ecode):
163 return err.Error(), code
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list