github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/internal/util/error.go (about)

     1  package util
     2  
     3  import (
     4  	"runtime"
     5  	"strconv"
     6  )
     7  
     8  type ErrorString string
     9  
    10  func (e ErrorString) Error() string { return string(e) }
    11  
    12  const (
    13  	NilErr       = ErrorString("sqlite3: invalid memory address or null pointer dereference")
    14  	OOMErr       = ErrorString("sqlite3: out of memory")
    15  	RangeErr     = ErrorString("sqlite3: index out of range")
    16  	NoNulErr     = ErrorString("sqlite3: missing NUL terminator")
    17  	NoBinaryErr  = ErrorString("sqlite3: no SQLite binary embed/set/loaded")
    18  	BadBinaryErr = ErrorString("sqlite3: invalid SQLite binary embed/set/loaded")
    19  	TimeErr      = ErrorString("sqlite3: invalid time value")
    20  	WhenceErr    = ErrorString("sqlite3: invalid whence")
    21  	OffsetErr    = ErrorString("sqlite3: invalid offset")
    22  	TailErr      = ErrorString("sqlite3: multiple statements")
    23  	IsolationErr = ErrorString("sqlite3: unsupported isolation level")
    24  	ValueErr     = ErrorString("sqlite3: unsupported value")
    25  	NoVFSErr     = ErrorString("sqlite3: no such vfs: ")
    26  )
    27  
    28  func AssertErr() ErrorString {
    29  	msg := "sqlite3: assertion failed"
    30  	if _, file, line, ok := runtime.Caller(1); ok {
    31  		msg += " (" + file + ":" + strconv.Itoa(line) + ")"
    32  	}
    33  	return ErrorString(msg)
    34  }
    35  
    36  func ErrorCodeString(rc uint32) string {
    37  	switch rc {
    38  	case ABORT_ROLLBACK:
    39  		return "sqlite3: abort due to ROLLBACK"
    40  	case ROW:
    41  		return "sqlite3: another row available"
    42  	case DONE:
    43  		return "sqlite3: no more rows available"
    44  	}
    45  	switch rc & 0xff {
    46  	case OK:
    47  		return "sqlite3: not an error"
    48  	case ERROR:
    49  		return "sqlite3: SQL logic error"
    50  	case INTERNAL:
    51  		break
    52  	case PERM:
    53  		return "sqlite3: access permission denied"
    54  	case ABORT:
    55  		return "sqlite3: query aborted"
    56  	case BUSY:
    57  		return "sqlite3: database is locked"
    58  	case LOCKED:
    59  		return "sqlite3: database table is locked"
    60  	case NOMEM:
    61  		return "sqlite3: out of memory"
    62  	case READONLY:
    63  		return "sqlite3: attempt to write a readonly database"
    64  	case INTERRUPT:
    65  		return "sqlite3: interrupted"
    66  	case IOERR:
    67  		return "sqlite3: disk I/O error"
    68  	case CORRUPT:
    69  		return "sqlite3: database disk image is malformed"
    70  	case NOTFOUND:
    71  		return "sqlite3: unknown operation"
    72  	case FULL:
    73  		return "sqlite3: database or disk is full"
    74  	case CANTOPEN:
    75  		return "sqlite3: unable to open database file"
    76  	case PROTOCOL:
    77  		return "sqlite3: locking protocol"
    78  	case FORMAT:
    79  		break
    80  	case SCHEMA:
    81  		return "sqlite3: database schema has changed"
    82  	case TOOBIG:
    83  		return "sqlite3: string or blob too big"
    84  	case CONSTRAINT:
    85  		return "sqlite3: constraint failed"
    86  	case MISMATCH:
    87  		return "sqlite3: datatype mismatch"
    88  	case MISUSE:
    89  		return "sqlite3: bad parameter or other API misuse"
    90  	case NOLFS:
    91  		break
    92  	case AUTH:
    93  		return "sqlite3: authorization denied"
    94  	case EMPTY:
    95  		break
    96  	case RANGE:
    97  		return "sqlite3: column index out of range"
    98  	case NOTADB:
    99  		return "sqlite3: file is not a database"
   100  	case NOTICE:
   101  		return "sqlite3: notification message"
   102  	case WARNING:
   103  		return "sqlite3: warning message"
   104  	}
   105  	return "sqlite3: unknown error"
   106  }