libduckdb_sys_queryscript/
error.rs

1use crate::duckdb_state;
2use std::error;
3use std::fmt;
4
5/// Error Codes
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum ErrorCode {
9    /// Internal logic error in SQLite
10    InternalMalfunction,
11    /// Access permission denied
12    PermissionDenied,
13    /// Callback routine requested an abort
14    OperationAborted,
15    /// The database file is locked
16    DatabaseBusy,
17    /// A table in the database is locked
18    DatabaseLocked,
19    /// A malloc() failed
20    OutOfMemory,
21    /// Attempt to write a readonly database
22    ReadOnly,
23    /// Operation terminated by sqlite3_interrupt()
24    OperationInterrupted,
25    /// Some kind of disk I/O error occurred
26    SystemIoFailure,
27    /// The database disk image is malformed
28    DatabaseCorrupt,
29    /// Unknown opcode in sqlite3_file_control()
30    NotFound,
31    /// Insertion failed because database is full
32    DiskFull,
33    /// Unable to open the database file
34    CannotOpen,
35    /// Database lock protocol error
36    FileLockingProtocolFailed,
37    /// The database schema changed
38    SchemaChanged,
39    /// String or BLOB exceeds size limit
40    TooBig,
41    /// Abort due to constraint violation
42    ConstraintViolation,
43    /// Data type mismatch
44    TypeMismatch,
45    /// Library used incorrectly
46    ApiMisuse,
47    /// Uses OS features not supported on host
48    NoLargeFileSupport,
49    /// Authorization denied
50    AuthorizationForStatementDenied,
51    /// 2nd parameter to sqlite3_bind out of range
52    ParameterOutOfRange,
53    /// File opened that is not a database file
54    NotADatabase,
55    /// SQL error or missing database
56    Unknown,
57}
58
59#[derive(Clone, Copy, Debug, PartialEq, Eq)]
60pub struct Error {
61    pub code: ErrorCode,
62    pub extended_code: duckdb_state,
63}
64
65impl Error {
66    pub fn new(result_code: duckdb_state) -> Error {
67        Error {
68            code: ErrorCode::Unknown,
69            extended_code: result_code,
70        }
71    }
72}
73
74impl fmt::Display for Error {
75    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76        write!(
77            f,
78            "Error code {}: {}",
79            self.extended_code,
80            code_to_str(self.extended_code)
81        )
82    }
83}
84
85impl error::Error for Error {
86    fn description(&self) -> &str {
87        code_to_str(self.extended_code)
88    }
89}
90
91pub fn code_to_str(_: duckdb_state) -> &'static str {
92    "Unknown error code"
93}