remove IOError from Parser + store only ErrorKind in LimboError

This commit is contained in:
pedrocarlo
2025-08-13 12:39:08 -03:00
parent 54c02b6ae0
commit d0c13f0104
6 changed files with 20 additions and 22 deletions

View File

@@ -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<std::io::Error> for LimboError {
fn from(value: std::io::Error) -> Self {
LimboError::IOError(value.kind())
}
}
impl From<std::io::ErrorKind> for LimboError {
fn from(value: std::io::ErrorKind) -> Self {
LimboError::IOError(value)
}
}
#[macro_export]
macro_rules! bail_parse_error {
($($arg:tt)*) => {

View File

@@ -48,10 +48,7 @@ impl IO for MemoryIO {
fn open_file(&self, path: &str, flags: OpenFlags, _direct: bool) -> Result<Arc<dyn File>> {
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(

View File

@@ -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(),

View File

@@ -2,10 +2,9 @@
use std::error::Error;
use std::fmt;
use std::io;
/// Error with position
pub trait ScanError: Error + From<io::Error> + Sized {
pub trait ScanError: Error + Sized {
/// Update the position where the error occurs
fn position(&mut self, line: u64, column: usize, offset: usize);
}

View File

@@ -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<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::Io(err)
}
}
impl From<ParserError> for Error {
fn from(err: ParserError) -> Self {
Self::ParserError(err, None, None)
@@ -118,7 +108,6 @@ impl From<ParserError> 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());

View File

@@ -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),