1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
use wick_config::error::ManifestError;
use wick_packet::TypeWrapper;

#[derive(thiserror::Error, Debug)]
#[allow(missing_docs)]
#[non_exhaustive]
pub enum Error {
  #[error("Invalid output for operations {}. At this time postgres operations can have at most one output named 'output' of type 'object'", .0.join(", "))]
  InvalidOutput(Vec<String>),

  #[error("Failed to fetch result of query: {0}")]
  Fetch(String),

  #[error("Failed to fetch result of exec: {0}")]
  Exec(String),

  #[error("Unknown database scheme '{0}'")]
  InvalidScheme(String),

  #[error(
    "To use in-memory SQLite databases, use the URL 'sqlite://memory'; to use a SQLite DB file, use a 'file://' URL"
  )]
  SqliteScheme,

  #[error("Failed to prepare arguments: {0}")]
  Prepare(String),

  #[error("Failed to connect to MsSqlServer: {0}")]
  MssqlConnect(String),

  #[error("Failed to connect to Postgres Server: {0}")]
  PostgresConnect(String),

  #[error("Failed to open to Sqlite DB: {0}")]
  SqliteConnect(String),

  #[error("{0}")]
  Pool(String),

  #[error("Failed to get connection from pool: {0}")]
  PoolConnection(String),

  #[error("Failed to start DB transaction")]
  TxStart,

  #[error("Failed to commit DB transaction")]
  TxCommit,

  #[error("Failed to rollback DB transaction")]
  TxRollback,

  #[error("Operation failed: {0}")]
  OperationFailed(String),

  #[error("SQL Query failed, check log for details")]
  QueryFailed,

  #[error("SQL error reported within stream: {0}")]
  ErrorInStream(String),

  #[error("Query failed: {0}")]
  Failed(String),

  #[error("Missing positional argument '{0}'")]
  MissingArgument(String),

  #[error("Missing input")]
  MissingInput,

  #[error("Operation '{0}' not found on this component")]
  MissingOperation(String),

  #[error("Could not find a value for input '{0}' to bind to a positional argument")]
  MissingPacket(String),

  #[error("Could not encode wick type {} with value '{}' into the DB's type for {1}. Try a different value, type, or coersion within the SQL query.",.0.type_signature(),.0.inner())]
  SqlServerEncodingFault(TypeWrapper, ConversionError),

  #[error(transparent)]
  ComponentError(wick_packet::Error),

  #[error("Database connection not initialized")]
  Uninitialized,

  #[error(transparent)]
  Configuration(#[from] ManifestError),

  #[error("Resource valid but its value could not be retrieved")]
  InvalidResourceConfig,

  #[error("Got a row with no data")]
  NoRow,
}

#[derive(thiserror::Error, Debug, Copy, Clone)]
pub enum ConversionError {
  #[error("i8")]
  I8,
  #[error("i16")]
  I16,
  #[error("i32")]
  I32,
  #[error("i64")]
  I64,
  #[error("u8")]
  U8,
  #[error("u16")]
  U16,
  #[error("u32")]
  U32,
  #[error("u64")]
  U64,
  #[error("f32")]
  F32,
  #[error("f64")]
  F64,
  #[error("bool")]
  Bool,
  #[error("string")]
  String,
  #[error("datetime")]
  Datetime,
  #[error("bytes")]
  Bytes,
  #[error("named")]
  Named,
  #[error("list")]
  List,
  #[error("optional")]
  Optional,
  #[error("map")]
  Map,
  #[error("link")]
  Link,
  #[error("object")]
  Object,
  #[error("anonymous struct")]
  AnonymousStruct,
}