Hi,
according to the manual page, ledger print can be used to reformat a
ledger file. As such I expect it to produce valid ledger syntax. The
following trips it up:
$ printf "bucket X\n2222/11/11 c\n Y 1\n"
bucket X
2222/11/11 c
Y 1
$ printf "bucket X\n2222/11/11 c\n Y 1\n" | ledger -f - print
2222/11/11 c
Y 1
$ printf "bucket X\n2222/11/11 c\n Y 1\n" | ledger -f - print | ledger -f - print; echo $?
While parsing file "", line 2:
While balancing transaction from streamed input:
Unbalanced remainder is:
1
Amount to balance against:
1
Error: Transaction does not balance
1
$
As you can see in the second command, the bucket stanza is dropped, but
the transaction is not balanced using the X bucket. Thus the third
invocation fails. I think ledger print should either retain the bucket
stanza or balance the transaction using the default bucket.
Please consider adding an autopkgtest or unittest for this issue.
Helmut
* Helmut Grohne <helmut@subdivi.de> [2023-06-28 20:40]: Note that there are a lot of bugs about `print` creating invalid syntax (see below). Some of them can be avoided with `print --raw` (but unfortunately not this one). Some related bugs: https://github.com/ledger/ledger/issues/1768 https://github.com/ledger/ledger/issues/1974 https://github.com/ledger/ledger/issues/2100 https://github.com/ledger/ledger/issues/1033 https://github.com/ledger/ledger/issues/1212
fixed 1039736 3.4.1-3+b1
Verified in a clean chroot with ledger 3.4.1-3+b1:
$ printf "bucket X\n2222/11/11 c\n Y 1\n" | ledger -f - print | ledger -f
- print
2222/11/11 c
Y 1
X
$ echo $?
--
Regards, Kirill Rekhov
Currently Debian Maintainer
GPG Fingerprint: 2640 769D FDA1 AAA0 F863 D1AE 5F2C 5905 519C E0A0
Debian Salsa: https://salsa.debian.org/krekhov
Debian Person: https://nm.debian.org/person/krekhov
Debian QA Page:
https://qa.debian.org/developer.php?login=krekhov.dev@gmail.com
GitHub: https://github.com/krekhovx