# Wrong error message in search

**URL:** <https://forums.ankiweb.net/t/wrong-error-message-in-search/16914>\
**Category:** Help\
**Created:** [January 21, 2022, 10:47pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914 "2022-01-21T22:47:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArthurMilchior](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/arthurmilchior/32/4684_2.png) [@ArthurMilchior](https://forums.ankiweb.net/u/ArthurMilchior)\
**Post date:** [January 21, 2022, 10:47pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/1 "2022-01-21T22:47:19Z")

</div>

How to reproduce:

in the browser, enter `*:`

Expected result:  
an understandable message in English

Actual result:

> DbError { info: “SqliteFailure(Error { code: Unknown, extended\_code: 1 }, Some("Expression tree is too large (maximum depth 1000)"))”, kind: Other }

Admittedly, I understand it but I suspect that it may be nice for user to get a simpler English sentence that do not reference sql or tree

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [January 21, 2022, 11:06pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/2 "2022-01-21T23:06:25Z")

</div>

The search string works for me: It returns all cards that have an empty field. Maybe it causes an error only in some situations (probably depending on your collection).

---

<div class="post-metadata">

**Author:** ![ArthurMilchior](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/arthurmilchior/32/4684_2.png) [@ArthurMilchior](https://forums.ankiweb.net/u/ArthurMilchior)\
**Post date:** [January 21, 2022, 11:21pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/3 "2022-01-21T23:21:04Z")

</div>

I suspect that the trouble occurs when you have too many card type and fields. Probably you’ll need a thousand different felds.

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [January 22, 2022, 9:14am UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/4 "2022-01-22T09:14:24Z")

</div>

That makes sense. Presumably `*:` could be special cased to be a lot more efficient.  
It also looks like we’re rebuilding the same regex for every field name comparison, which is quite wasteful.

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [January 22, 2022, 10:39pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/5 "2022-01-22T22:39:46Z")

</div>

I opened a PR on this:

> <https://github.com/ankitects/anki/pull/1622>
>
> https://forums.ankiweb.net/t/wrong-error-message-in-search/16914
> 
> With my test… collection, the first commit brings down search time for \`\*:\` from 0.23s to 0.18s, and the second one to 0.11s. The tree depth error shouldn't occur either.
> 
> Unfortunately, 79140cf4b519c634798be5b36d9dabb9fca0787c doesn't work for regex searches, because if there is an \`^\` or \`$\`, it will fail to match.
> @dae, what is the reason regex field searches behave differently from plain field searches and do not require a full match? I'm asking because if they did, \`^\` and \`$\` wouldn't match anyway and the shortcut wouldn't make a difference.

---

<div class="post-metadata">

**Author:** ![ArthurMilchior](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/arthurmilchior/32/4684_2.png) [@ArthurMilchior](https://forums.ankiweb.net/u/ArthurMilchior)\
**Post date:** [January 23, 2022, 2:18pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/6 "2022-01-23T14:18:23Z")

</div>

I’d like to note that it does not solve the original problem I mentioned, which is that sql can send exceptions that are not catched and shown in an hard to understand way if you don’t know what sql is.

I love having `*:foo` as a special case, being able to easily search any field with an exact match. And `"(?i)(^|\x1f){}($|\x1f)",` seems reall cool (I don’t speak rust, but I still got the regexp part)

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [January 23, 2022, 2:40pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/7 "2022-01-23T14:40:23Z")

</div>

Well, this error could happen for a number of reasons, so it’s hardly possible to map it to a helpful user error. Instead we should take care that it doesn’t happen in valid use cases like yours in my opinion.

---

<div class="post-metadata">

**Author:** ![ArthurMilchior](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/arthurmilchior/32/4684_2.png) [@ArthurMilchior](https://forums.ankiweb.net/u/ArthurMilchior)\
**Post date:** [January 23, 2022, 8:29pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/8 "2022-01-23T20:29:26Z")

</div>

You can, at the very least, prefix it with a human message of the kind.

There was an error with the search. Please report the following message on [forums.ankiweb.net](http://forums.ankiweb.net)  
and maybe detect the “expression tree is too large” to indicate “or try a simpler search”

---

<div class="post-metadata">

**Author:** ![Rumo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/rumo/32/1505_2.png) [@Rumo](https://forums.ankiweb.net/u/Rumo)\
**Post date:** [January 24, 2022, 10:30am UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/9 "2022-01-24T10:30:56Z")

</div>

I think you couldn’t even be sure that it’s a search error, because it might have been other parts of Anki calling the database under the hood.  
However, prefixing any unexpected errors with some helpful instructions sounds reasonable. Maybe this can be accomplished in the Python backend code without too much trouble.

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [January 24, 2022, 1:04pm UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/10 "2022-01-24T13:04:19Z")

</div>

You are right in principle Rumo, but I suspect a pragmatic approach could work here. I don’t recall any reports of this error being triggered outside the search code, so it’s probably not going to do much harm if we look for “Expression tree too large”, and convert the full text to something like “Search too complex, please simplify” in that case. Not thrilled about string comparisons, but I don’t think SQLite exposes a unique enum variant for us.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 1, 2023, 4:34am UTC](https://forums.ankiweb.net/t/wrong-error-message-in-search/16914/11 "2023-05-01T04:34:46Z")

</div>


