libduckdb_sys_queryscript/
error.rs1use crate::duckdb_state;
2use std::error;
3use std::fmt;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum ErrorCode {
9 InternalMalfunction,
11 PermissionDenied,
13 OperationAborted,
15 DatabaseBusy,
17 DatabaseLocked,
19 OutOfMemory,
21 ReadOnly,
23 OperationInterrupted,
25 SystemIoFailure,
27 DatabaseCorrupt,
29 NotFound,
31 DiskFull,
33 CannotOpen,
35 FileLockingProtocolFailed,
37 SchemaChanged,
39 TooBig,
41 ConstraintViolation,
43 TypeMismatch,
45 ApiMisuse,
47 NoLargeFileSupport,
49 AuthorizationForStatementDenied,
51 ParameterOutOfRange,
53 NotADatabase,
55 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}