#1039736 ledger print creates invalid syntax

Package:
ledger
Source:
ledger
Description:
command-line double-entry accounting program
Submitter:
Helmut Grohne
Date:
2026-03-12 17:41:08 UTC
Severity:
normal
Tags:
#1039736#5
Date:
2023-06-28 18:40:27 UTC
From:
To:
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

#1039736#10
Date:
2023-12-12 03:01:55 UTC
From:
To:
* 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