Skip to content

Expose whether a regex_automata error was a size overflow or another error #1236

Closed
@konstin

Description

@konstin

I'm building an DFA from user provided expressions for a fast-path optimization, which I can skip when the DFA would be too large. Currently, there is no way to tell whether building the DFA failed because there was a syntax error (which I want to raise to the user), or because there was a size overflow (which is non-fatal). It would be great if regex_automata::dfa::dense::BuildError would allow inspecting whether it's a size error.

Motivating example:

let dfa_builder = dfa::dense::Builder::new()
    .configure(
        dfa::dense::Config::new()
            // DFA can grow exponentially, in which case we bail out
            .dfa_size_limit(Some(DFA_SIZE_LIMIT))
            .determinize_size_limit(Some(DFA_SIZE_LIMIT)),
    )
    .build_many(&regexes);
let dfa = match dfa_builder {
    Ok(dfa) => Some(dfa),
    Err(_) => {
        // TODO(konsti): `regex_automata::dfa::dense::BuildError` should allow asking whether
        // is a size error
        warn!(
            "Glob expressions regex is larger than {DFA_SIZE_LIMIT} bytes, \
            falling back to full directory traversal!"
        );
        None
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions