|
1 | 1 | use anyhow::{anyhow, bail, Result};
|
| 2 | +use metrics::counter; |
2 | 3 | use std::collections::HashMap;
|
3 | 4 |
|
4 | 5 | use super::result_builder::SingleStatementBuilder;
|
@@ -206,39 +207,46 @@ fn catch_stmt_error(sqld_error: SqldError) -> anyhow::Error {
|
206 | 207 | }
|
207 | 208 |
|
208 | 209 | pub fn stmt_error_from_sqld_error(sqld_error: SqldError) -> Result<StmtError, SqldError> {
|
209 |
| - Ok(match sqld_error { |
210 |
| - SqldError::LibSqlInvalidQueryParams(source) => StmtError::ArgsInvalid { source }, |
211 |
| - SqldError::LibSqlTxTimeout => StmtError::TransactionTimeout, |
212 |
| - SqldError::LibSqlTxBusy => StmtError::TransactionBusy, |
| 210 | + let result = match sqld_error { |
| 211 | + SqldError::LibSqlInvalidQueryParams(source) => Ok(StmtError::ArgsInvalid { source }), |
| 212 | + SqldError::LibSqlTxTimeout => Ok(StmtError::TransactionTimeout), |
| 213 | + SqldError::LibSqlTxBusy => Ok(StmtError::TransactionBusy), |
213 | 214 | SqldError::BuilderError(QueryResultBuilderError::ResponseTooLarge(_)) => {
|
214 |
| - StmtError::ResponseTooLarge |
| 215 | + Ok(StmtError::ResponseTooLarge) |
215 | 216 | }
|
216 |
| - SqldError::Blocked(reason) => StmtError::Blocked { reason }, |
217 |
| - SqldError::RpcQueryError(e) => StmtError::Proxy(e.message), |
| 217 | + SqldError::Blocked(reason) => Ok(StmtError::Blocked { reason }), |
| 218 | + SqldError::RpcQueryError(e) => Ok(StmtError::Proxy(e.message)), |
218 | 219 | SqldError::RusqliteError(rusqlite_error)
|
219 | 220 | | SqldError::RusqliteErrorExtended(rusqlite_error, _) => match rusqlite_error {
|
220 |
| - rusqlite::Error::SqliteFailure(sqlite_error, Some(message)) => StmtError::SqliteError { |
221 |
| - source: sqlite_error, |
222 |
| - message, |
223 |
| - }, |
224 |
| - rusqlite::Error::SqliteFailure(sqlite_error, None) => StmtError::SqliteError { |
| 221 | + rusqlite::Error::SqliteFailure(sqlite_error, Some(message)) => { |
| 222 | + Ok(StmtError::SqliteError { |
| 223 | + source: sqlite_error, |
| 224 | + message, |
| 225 | + }) |
| 226 | + } |
| 227 | + rusqlite::Error::SqliteFailure(sqlite_error, None) => Ok(StmtError::SqliteError { |
225 | 228 | message: sqlite_error.to_string(),
|
226 | 229 | source: sqlite_error,
|
227 |
| - }, |
| 230 | + }), |
228 | 231 | rusqlite::Error::SqlInputError {
|
229 | 232 | error: sqlite_error,
|
230 | 233 | msg: message,
|
231 | 234 | offset,
|
232 | 235 | ..
|
233 |
| - } => StmtError::SqlInputError { |
| 236 | + } => Ok(StmtError::SqlInputError { |
234 | 237 | source: sqlite_error,
|
235 | 238 | message,
|
236 | 239 | offset,
|
237 |
| - }, |
238 |
| - rusqlite_error => return Err(SqldError::RusqliteError(rusqlite_error)), |
| 240 | + }), |
| 241 | + rusqlite_error => Err(SqldError::RusqliteError(rusqlite_error)), |
239 | 242 | },
|
240 |
| - sqld_error => return Err(sqld_error), |
241 |
| - }) |
| 243 | + sqld_error => Err(sqld_error), |
| 244 | + }; |
| 245 | + |
| 246 | + let code = result.as_ref().map(|x| x.code()).unwrap_or("UKNOWN"); |
| 247 | + counter!("libsql_server_hrana_step_errors", 1, "code" => code); |
| 248 | + |
| 249 | + result |
242 | 250 | }
|
243 | 251 |
|
244 | 252 | pub fn proto_error_from_stmt_error(error: &StmtError) -> hrana::proto::Error {
|
|
0 commit comments