github.com/aergoio/aergo@v1.3.1/contract/error.go (about)

     1  // Copyright (C) 2014 Yasuhiro Matsumoto <mattn.jp@gmail.com>.
     2  //
     3  // Use of this source code is governed by an MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package contract
     7  
     8  import "C"
     9  
    10  // ErrNo inherit errno.
    11  type ErrNo int
    12  
    13  // ErrNoMask is mask code.
    14  const ErrNoMask C.int = 0xff
    15  
    16  // ErrNoExtended is extended errno.
    17  type ErrNoExtended int
    18  
    19  // Error implement sqlite error code.
    20  type Error struct {
    21  	Code         ErrNo         /* The error code returned by SQLite */
    22  	ExtendedCode ErrNoExtended /* The extended error code returned by SQLite */
    23  	err          string        /* The error string returned by sqlite3_errmsg(),
    24  	this usually contains more specific details. */
    25  }
    26  
    27  // result codes from http://www.sqlite.org/c3ref/c_abort.html
    28  var (
    29  	ErrError      = ErrNo(1)  /* SQL error or missing database */
    30  	ErrInternal   = ErrNo(2)  /* Internal logic error in SQLite */
    31  	ErrPerm       = ErrNo(3)  /* Access permission denied */
    32  	ErrAbort      = ErrNo(4)  /* Callback routine requested an abort */
    33  	ErrBusy       = ErrNo(5)  /* The database file is locked */
    34  	ErrLocked     = ErrNo(6)  /* A table in the database is locked */
    35  	ErrNomem      = ErrNo(7)  /* A malloc() failed */
    36  	ErrReadonly   = ErrNo(8)  /* Attempt to write a readonly database */
    37  	ErrInterrupt  = ErrNo(9)  /* Operation terminated by sqlite3_interrupt() */
    38  	ErrIoErr      = ErrNo(10) /* Some kind of disk I/O error occurred */
    39  	ErrCorrupt    = ErrNo(11) /* The database disk image is malformed */
    40  	ErrNotFound   = ErrNo(12) /* Unknown opcode in sqlite3_file_control() */
    41  	ErrFull       = ErrNo(13) /* Insertion failed because database is full */
    42  	ErrCantOpen   = ErrNo(14) /* Unable to open the database file */
    43  	ErrProtocol   = ErrNo(15) /* Database lock protocol error */
    44  	ErrEmpty      = ErrNo(16) /* Database is empty */
    45  	ErrSchema     = ErrNo(17) /* The database schema changed */
    46  	ErrTooBig     = ErrNo(18) /* String or BLOB exceeds size limit */
    47  	ErrConstraint = ErrNo(19) /* Abort due to constraint violation */
    48  	ErrMismatch   = ErrNo(20) /* Data type mismatch */
    49  	ErrMisuse     = ErrNo(21) /* Library used incorrectly */
    50  	ErrNoLFS      = ErrNo(22) /* Uses OS features not supported on host */
    51  	ErrAuth       = ErrNo(23) /* Authorization denied */
    52  	ErrFormat     = ErrNo(24) /* Auxiliary database format error */
    53  	ErrRange      = ErrNo(25) /* 2nd parameter to sqlite3_bind out of range */
    54  	ErrNotADB     = ErrNo(26) /* File opened that is not a database file */
    55  	ErrNotice     = ErrNo(27) /* Notifications from sqlite3_log() */
    56  	ErrWarning    = ErrNo(28) /* Warnings from sqlite3_log() */
    57  )
    58  
    59  // Error return error message from errno.
    60  func (err ErrNo) Error() string {
    61  	return Error{Code: err}.Error()
    62  }
    63  
    64  // Extend return extended errno.
    65  func (err ErrNo) Extend(by int) ErrNoExtended {
    66  	return ErrNoExtended(int(err) | (by << 8))
    67  }
    68  
    69  // Error return error message that is extended code.
    70  func (err ErrNoExtended) Error() string {
    71  	return Error{Code: ErrNo(C.int(err) & ErrNoMask), ExtendedCode: err}.Error()
    72  }
    73  
    74  func (err Error) Error() string {
    75  	if err.err != "" {
    76  		return err.err
    77  	}
    78  	return errorString(err)
    79  }
    80  
    81  // result codes from http://www.sqlite.org/c3ref/c_abort_rollback.html
    82  var (
    83  	ErrIoErrRead              = ErrIoErr.Extend(1)
    84  	ErrIoErrShortRead         = ErrIoErr.Extend(2)
    85  	ErrIoErrWrite             = ErrIoErr.Extend(3)
    86  	ErrIoErrFsync             = ErrIoErr.Extend(4)
    87  	ErrIoErrDirFsync          = ErrIoErr.Extend(5)
    88  	ErrIoErrTruncate          = ErrIoErr.Extend(6)
    89  	ErrIoErrFstat             = ErrIoErr.Extend(7)
    90  	ErrIoErrUnlock            = ErrIoErr.Extend(8)
    91  	ErrIoErrRDlock            = ErrIoErr.Extend(9)
    92  	ErrIoErrDelete            = ErrIoErr.Extend(10)
    93  	ErrIoErrBlocked           = ErrIoErr.Extend(11)
    94  	ErrIoErrNoMem             = ErrIoErr.Extend(12)
    95  	ErrIoErrAccess            = ErrIoErr.Extend(13)
    96  	ErrIoErrCheckReservedLock = ErrIoErr.Extend(14)
    97  	ErrIoErrLock              = ErrIoErr.Extend(15)
    98  	ErrIoErrClose             = ErrIoErr.Extend(16)
    99  	ErrIoErrDirClose          = ErrIoErr.Extend(17)
   100  	ErrIoErrSHMOpen           = ErrIoErr.Extend(18)
   101  	ErrIoErrSHMSize           = ErrIoErr.Extend(19)
   102  	ErrIoErrSHMLock           = ErrIoErr.Extend(20)
   103  	ErrIoErrSHMMap            = ErrIoErr.Extend(21)
   104  	ErrIoErrSeek              = ErrIoErr.Extend(22)
   105  	ErrIoErrDeleteNoent       = ErrIoErr.Extend(23)
   106  	ErrIoErrMMap              = ErrIoErr.Extend(24)
   107  	ErrIoErrGetTempPath       = ErrIoErr.Extend(25)
   108  	ErrIoErrConvPath          = ErrIoErr.Extend(26)
   109  	ErrLockedSharedCache      = ErrLocked.Extend(1)
   110  	ErrBusyRecovery           = ErrBusy.Extend(1)
   111  	ErrBusySnapshot           = ErrBusy.Extend(2)
   112  	ErrCantOpenNoTempDir      = ErrCantOpen.Extend(1)
   113  	ErrCantOpenIsDir          = ErrCantOpen.Extend(2)
   114  	ErrCantOpenFullPath       = ErrCantOpen.Extend(3)
   115  	ErrCantOpenConvPath       = ErrCantOpen.Extend(4)
   116  	ErrCorruptVTab            = ErrCorrupt.Extend(1)
   117  	ErrReadonlyRecovery       = ErrReadonly.Extend(1)
   118  	ErrReadonlyCantLock       = ErrReadonly.Extend(2)
   119  	ErrReadonlyRollback       = ErrReadonly.Extend(3)
   120  	ErrReadonlyDbMoved        = ErrReadonly.Extend(4)
   121  	ErrAbortRollback          = ErrAbort.Extend(2)
   122  	ErrConstraintCheck        = ErrConstraint.Extend(1)
   123  	ErrConstraintCommitHook   = ErrConstraint.Extend(2)
   124  	ErrConstraintForeignKey   = ErrConstraint.Extend(3)
   125  	ErrConstraintFunction     = ErrConstraint.Extend(4)
   126  	ErrConstraintNotNull      = ErrConstraint.Extend(5)
   127  	ErrConstraintPrimaryKey   = ErrConstraint.Extend(6)
   128  	ErrConstraintTrigger      = ErrConstraint.Extend(7)
   129  	ErrConstraintUnique       = ErrConstraint.Extend(8)
   130  	ErrConstraintVTab         = ErrConstraint.Extend(9)
   131  	ErrConstraintRowID        = ErrConstraint.Extend(10)
   132  	ErrNoticeRecoverWAL       = ErrNotice.Extend(1)
   133  	ErrNoticeRecoverRollback  = ErrNotice.Extend(2)
   134  	ErrWarningAutoIndex       = ErrWarning.Extend(1)
   135  )