mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 22:46:40 +01:00
In this commit, we use exhaustive build tags to ensure that we can always build the `sqlbase` package, independent of the set build tags. To do this, we move the type declarations _into_ the parsing functions. This then allows us to create two versions for each db: with the db, and without it. To avoid a module tag round trip to get this working, we use a local replace for now. Once this is merged in, we can do the tag (along side rc3), then remove the replace.
37 lines
825 B
Go
37 lines
825 B
Go
//go:build kvdb_sqlite && !(windows && (arm || 386)) && !(linux && (ppc64 || mips || mipsle || mips64))
|
|
|
|
package sqlbase
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"modernc.org/sqlite"
|
|
sqlite3 "modernc.org/sqlite/lib"
|
|
)
|
|
|
|
// parseSqliteError attempts to parse a sqlite error as a database agnostic
|
|
// SQL error.
|
|
func parseSqliteError(err error) error {
|
|
var sqliteErr *sqlite.Error
|
|
if !errors.As(err, &sqliteErr) {
|
|
return nil
|
|
}
|
|
|
|
switch sqliteErr.Code() {
|
|
// Handle unique constraint violation error.
|
|
case sqlite3.SQLITE_CONSTRAINT_UNIQUE:
|
|
return &ErrSQLUniqueConstraintViolation{
|
|
DBError: sqliteErr,
|
|
}
|
|
|
|
// Database is currently busy, so we'll need to try again.
|
|
case sqlite3.SQLITE_BUSY:
|
|
return &ErrSerializationError{
|
|
DBError: sqliteErr,
|
|
}
|
|
|
|
default:
|
|
return fmt.Errorf("unknown sqlite error: %w", sqliteErr)
|
|
}
|
|
}
|