ValueError: String too long (66 lines) - why?

23 views
Skip to first unread message

Stefano Zacchiroli

unread,
Aug 2, 2023, 5:43:30 AM8/2/23
to bean...@googlegroups.com
Heya, I'm hitting this error in the beancount v2 C parser (quoting from
beancount/parser/tokens.c):

if (lines > LONG_STRING_LINES_MAX) {
PyErr_Format(PyExc_ValueError, "String too long (%d lines)", lines);
free(unescaped);
return NULL;
}

What's the reason for that test/check?

(Curiously enough, I'm hitting it only from within Fava, whereas
bean-check standalone does not complain about that, not sure why.)

In case you're curious, such a long string comes from a specification
for the validate plugin:
https://github.com/zacchiro/beancount-plugins-zack/blob/master/validate.py
Arguably, it could/should just go to a separate file, referenced from
the beancount ledger, which would make the string trivially short, but
meh, it still seems to be an arbitrary restriction in the parser. What
am I missing?

Cheers

PS No, I cannot just switch to v3 and make this goes away, as Fava is
still on v2.

--
Stefano Zacchiroli . za...@upsilon.cc . https://upsilon.cc/zack _. ^ ._
Full professor of Computer Science o o o \/|V|\/
Télécom Paris, Polytechnic Institute of Paris o o o </> <\>
Co-founder & CTO Software Heritage o o o o /\|^|/\
https://twitter.com/zacchiro . https://mastodon.xyz/@zacchiro '" V "'

Daniele Nicolodi

unread,
Aug 2, 2023, 8:48:01 AM8/2/23
to bean...@googlegroups.com
On 02/08/23 11:43, Stefano Zacchiroli wrote:
> Heya, I'm hitting this error in the beancount v2 C parser (quoting from
> beancount/parser/tokens.c):
>
> if (lines > LONG_STRING_LINES_MAX) {
> PyErr_Format(PyExc_ValueError, "String too long (%d lines)", lines);
> free(unescaped);
> return NULL;
> }
>
> What's the reason for that test/check?

The idea is to detect instances where the user forgot a closing quote.
However, for how a beancount ledger is usually structured, it is very
hard to hit the line count limit before the ledger contains an unrelated
quote character that get interpreted as the closing quote.

IIRC I wanted to remove the check when I restructured the parser, but
Martin wanted to keep it. The compromise was to set the line count limit
to a relatively large number, 64, which makes hitting the limit in case
of a syntax error even less likely, and thus the check less useful.
Lately the limit as been increased again to 256, but a version of
beancount with the limit raised has not been released yet. The limit in
v3 is still there and set to 256.

Probably installing v2 from source solves your immediate need, but I
think we should just remove the limit.

Cheers,
Dan

Martin Blais

unread,
Aug 2, 2023, 9:41:56 AM8/2/23
to bean...@googlegroups.com
Happy to raise or remove the limit in v2 if you want.


--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/00ac805b-1f2a-e934-3ae3-1865c803b5cf%40grinta.net.

Stefano Zacchiroli

unread,
Aug 2, 2023, 2:45:50 PM8/2/23
to bean...@googlegroups.com
On Wed, Aug 02, 2023 at 09:39:40PM +0800, Martin Blais wrote:
> Happy to raise or remove the limit in v2 if you want.

That would be nice (+ publishing a new minor version on PyPI ;-)),
thanks! And thanks also to Daniele for explaining the rationale behind
this limitation.

My 2 cents on the rationale is that it's an odd trade-off. It doesn't go
all the way of trying to detect that the long string is *actually*
beancount markup that ended up in a string by mistake; hence when it is
the case it provides a potentially misleading error message ("string too
long"); and at the same time rejects (arguably) valid inputs like mine.
These for me are good arguments for dropping removing the limit
entirely. YMMV.

Cheers

Martin Blais

unread,
Aug 2, 2023, 7:20:55 PM8/2/23
to Beancount
Send me a patch. Im not home and have only a minimal dev setup on an old laptop and the odd late hour free every 3,4 days

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages