Skip to content

Commit 333324c

Browse files
committed
doc: add more explanation to 'CompiledTooBig' error
The existing docs were pretty paltry, and it turns out we can be a bit more helpful for folks when they hit this error. Fixes #846
1 parent d49ed1c commit 333324c

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/error.rs

+20-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,26 @@ use std::iter::repeat;
66
pub enum Error {
77
/// A syntax error.
88
Syntax(String),
9-
/// The compiled program exceeded the set size limit.
10-
/// The argument is the size limit imposed.
9+
/// The compiled program exceeded the set size
10+
/// limit. The argument is the size limit imposed by
11+
/// [`RegexBuilder::size_limit`](crate::RegexBuilder::size_limit). Even
12+
/// when not configured explicitly, it defaults to a reasonable limit.
13+
///
14+
/// If you're getting this error, it occurred because your regex has been
15+
/// compiled to an intermediate state that is too big. It is important to
16+
/// note that exceeding this limit does _not_ mean the regex is too big to
17+
/// _work_, but rather, the regex is big enough that it may wind up being
18+
/// surprisingly slow when used in a search. In other words, this error is
19+
/// meant to be a practical heuristic for avoiding a performance footgun,
20+
/// and especially so for the case where the regex pattern is coming from
21+
/// an untrusted source.
22+
///
23+
/// There are generally two ways to move forward if you hit this error.
24+
/// The first is to find some way to use a smaller regex. The second is to
25+
/// increase the size limit via `RegexBuilder::size_limit`. However, if
26+
/// your regex pattern is not from a trusted source, then neither of these
27+
/// approaches may be appropriate. Instead, you'll have to determine just
28+
/// how big of a regex you want to allow.
1129
CompiledTooBig(usize),
1230
/// Hints that destructuring should not be exhaustive.
1331
///

0 commit comments

Comments
 (0)