diff --git a/core/error.rs b/core/error.rs index d65191bff..fd386757b 100644 --- a/core/error.rs +++ b/core/error.rs @@ -1,6 +1,6 @@ use thiserror::Error; -#[derive(Debug, Error, miette::Diagnostic)] +#[derive(Debug, Clone, Error, miette::Diagnostic)] pub enum LimboError { #[error("Corrupt database: {0}")] Corrupt(String), @@ -24,7 +24,7 @@ pub enum LimboError { #[error("Transaction error: {0}")] TxError(String), #[error("I/O error: {0}")] - IOError(#[from] std::io::Error), + IOError(std::io::ErrorKind), #[cfg(all(target_os = "linux", feature = "io_uring"))] #[error("I/O error: {0}")] UringIOError(String), @@ -85,6 +85,19 @@ pub enum LimboError { PlanningError(String), } +// We only propagate the error kind +impl From for LimboError { + fn from(value: std::io::Error) -> Self { + LimboError::IOError(value.kind()) + } +} + +impl From for LimboError { + fn from(value: std::io::ErrorKind) -> Self { + LimboError::IOError(value) + } +} + #[macro_export] macro_rules! bail_parse_error { ($($arg:tt)*) => { diff --git a/core/io/memory.rs b/core/io/memory.rs index 29ac4f2be..280d36bd8 100644 --- a/core/io/memory.rs +++ b/core/io/memory.rs @@ -48,10 +48,7 @@ impl IO for MemoryIO { fn open_file(&self, path: &str, flags: OpenFlags, _direct: bool) -> Result> { let mut files = self.files.lock().unwrap(); if !files.contains_key(path) && !flags.contains(OpenFlags::Create) { - return Err(LimboError::IOError(std::io::Error::new( - std::io::ErrorKind::NotFound, - "file not found", - ))); + return Err(LimboError::IOError(std::io::ErrorKind::NotFound)); } if !files.contains_key(path) { files.insert( diff --git a/core/vdbe/sorter.rs b/core/vdbe/sorter.rs index 0c06336ae..72d26d510 100644 --- a/core/vdbe/sorter.rs +++ b/core/vdbe/sorter.rs @@ -313,7 +313,7 @@ impl Sorter { let chunk_file = match &self.temp_file { Some(temp_file) => temp_file.file.clone(), None => { - let temp_dir = tempfile::tempdir().map_err(LimboError::IOError)?; + let temp_dir = tempfile::tempdir()?; let chunk_file_path = temp_dir.as_ref().join("chunk_file"); let chunk_file = self.io.open_file( chunk_file_path.to_str().unwrap(), diff --git a/vendored/sqlite3-parser/src/lexer/scan.rs b/vendored/sqlite3-parser/src/lexer/scan.rs index 9bdaefa71..b84f7d98c 100644 --- a/vendored/sqlite3-parser/src/lexer/scan.rs +++ b/vendored/sqlite3-parser/src/lexer/scan.rs @@ -2,10 +2,9 @@ use std::error::Error; use std::fmt; -use std::io; /// Error with position -pub trait ScanError: Error + From + Sized { +pub trait ScanError: Error + Sized { /// Update the position where the error occurs fn position(&mut self, line: u64, column: usize, offset: usize); } diff --git a/vendored/sqlite3-parser/src/lexer/sql/error.rs b/vendored/sqlite3-parser/src/lexer/sql/error.rs index b85dad504..71d46e269 100644 --- a/vendored/sqlite3-parser/src/lexer/sql/error.rs +++ b/vendored/sqlite3-parser/src/lexer/sql/error.rs @@ -1,17 +1,14 @@ use std::error; use std::fmt; -use std::io; use crate::lexer::scan::ScanError; use crate::parser::ParserError; /// SQL lexer and parser errors #[non_exhaustive] -#[derive(Debug, miette::Diagnostic)] +#[derive(Debug, Clone, miette::Diagnostic)] #[diagnostic()] pub enum Error { - /// I/O Error - Io(io::Error), /// Lexer error UnrecognizedToken( Option<(u64, usize)>, @@ -73,7 +70,6 @@ pub enum Error { impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - Self::Io(ref err) => err.fmt(f), Self::UnrecognizedToken(pos, _) => { write!(f, "unrecognized token at {:?}", pos.unwrap()) } @@ -103,12 +99,6 @@ impl fmt::Display for Error { impl error::Error for Error {} -impl From for Error { - fn from(err: io::Error) -> Self { - Self::Io(err) - } -} - impl From for Error { fn from(err: ParserError) -> Self { Self::ParserError(err, None, None) @@ -118,7 +108,6 @@ impl From for Error { impl ScanError for Error { fn position(&mut self, line: u64, column: usize, offset: usize) { match *self { - Self::Io(_) => {} Self::UnrecognizedToken(ref mut pos, ref mut src) => { *pos = Some((line, column)); *src = Some((offset).into()); diff --git a/vendored/sqlite3-parser/src/parser/mod.rs b/vendored/sqlite3-parser/src/parser/mod.rs index 2f9d40f84..58fdc62f9 100644 --- a/vendored/sqlite3-parser/src/parser/mod.rs +++ b/vendored/sqlite3-parser/src/parser/mod.rs @@ -16,7 +16,7 @@ use crate::dialect::Token; use ast::{Cmd, ExplainKind, Name, Stmt}; /// Parser error -#[derive(Debug, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum ParserError { /// Syntax error SyntaxError(String),