Skip to content

run_query panics on incomplete Prolog queries #3235

@exlee

Description

@exlee

Hi,

I wrote pikchr.pl.

Tried to integrate Scryer first, but it panics in a way I couldn't easily fix. It seems that panics come from token parsing (see code below).

pub fn run_query(&mut self, query: impl Into<String>) -> QueryState<'_> {
let mut parser = Parser::new(
Stream::from_owned_string(query.into(), &mut self.machine_st.arena),
&mut self.machine_st,
);
let op_dir = CompositeOpDir::new(&self.indices.op_dir, None);
let term = parser
.read_term(&op_dir, Tokens::Default)
.expect("Failed to parse query");

I get these panics because I'm processing user input in real time, something that's guaranteed to be 95% incomplete.

Not sure how deep the code goes, but worst case scenario this could be fixed with introduction of either Result<_,_> version

pub fn run_query_safe(&mut self, query: impl Into<String>) -> Result<QueryState<'_>>`

or Option<_> version (it looks like the only failure is token parsing, allocation error probably should cause hard panic anyway)

pub fn run_query_safe(&mut self, query: impl Into<String>) -> Option<QueryState<'_>>`

If any solution is acceptable let me know, I can introduce a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions