Skip to content

Updated parse_infix(..) in mysql.rs and sqlite.rs to handle error rather than unwrap()#2207

Open
RPG-Alex wants to merge 5 commits intoapache:mainfrom
RPG-Alex:mysql_panic
Open

Updated parse_infix(..) in mysql.rs and sqlite.rs to handle error rather than unwrap()#2207
RPG-Alex wants to merge 5 commits intoapache:mainfrom
RPG-Alex:mysql_panic

Conversation

@RPG-Alex
Copy link

@RPG-Alex RPG-Alex commented Feb 7, 2026

Previously for both sqlite and mysql the parse_infix would panic if passed parser: &mut crate::parser::Parser returned an error:

    fn parse_infix(
        &self,
        parser: &mut crate::parser::Parser,
        expr: &crate::ast::Expr,
        _precedence: u8,
    ) -> Option<Result<crate::ast::Expr, ParserError>> {
        // Parse DIV as an operator
        if parser.parse_keyword(Keyword::DIV) {
            Some(Ok(Expr::BinaryOp {
                left: Box::new(expr.clone()),
                op: BinaryOperator::MyIntegerDivide,
                right: Box::new(parser.parse_expr().unwrap()),
            }))
        } else {
            None
        }
    }

Now Errors are being passed, and the parse_expr() error returned will be returned for parse_infix rather than panic:

    fn parse_infix(
        &self,
        parser: &mut crate::parser::Parser,
        expr: &crate::ast::Expr,
        _precedence: u8,
    ) -> Option<Result<crate::ast::Expr, ParserError>> {
        // Parse DIV as an operator
        if parser.parse_keyword(Keyword::DIV) {
            let left = Box::new(expr.clone());
            let right = Box::new(match parser.parse_expr() {
                Ok(expr) => expr,
                Err(e) => return Some(Err(e)),
            });
            Some(Ok(Expr::BinaryOp {
                left,
                op: BinaryOperator::MyIntegerDivide,
                right,
            }))
        } else {
            None
        }
    }

@RPG-Alex
Copy link
Author

RPG-Alex commented Feb 7, 2026

I realized the sqlite.rs parse_infix() was already patched. My PR only applies to mysql.rs now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant