Ledger 3.3.2 change in commodity format sub-directive handling

54 views
Skip to first unread message

Scott Carpenter

unread,
Jun 4, 2023, 8:23:06 AM6/4/23
to Ledger
After updating to 3.3.2, I was getting errors like this with my commodities:

While parsing file <something.ldg>, line 6:
Error: commodity directive symbol abc and format directive symbol  should be the same


Note the two spaces between "symbol" and "should". Looks like there is no format directive symbol. Commodities look like this:

commodity $
    format $ 1,000.00
    default

commodity abc
    format 1,000.000000

commodity xyz
    format 1,000.000


And many more entries. I've been using these for many years. Every format line after the first one produced an error like the above when I ran the file through ledger.

Adding the commodity to the format line makes the error go away:

commodity abc
    format abc 1,000.000000

Was I doing it wrong all this time and just getting away with it?

Figured I'd share as an FYI that something changed with this, and to help others that might run into the same error.

Thank you!

Scott Carpenter

unread,
Jun 4, 2023, 9:00:14 AM6/4/23
to Ledger
I see now that if I use, say:

commodity xyz
    format 1,000.000 xyz

Putting the commodity last, things behave the same  as before with my output.

Martin Michlmayr

unread,
Jun 4, 2023, 11:30:13 AM6/4/23
to ledge...@googlegroups.com
I think this works as expected (now), but maybe it needs to be
documented better. "format" requires an example of how the commodity
is to be used - you have to include the commodity because some people
(or regions) put it before the number and some people after.



* Scott Carpenter <scarp...@gmail.com> [2023-06-04 06:00]:
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Ledger" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/c12415e0-8882-4f43-bb1c-71993986f803n%40googlegroups.com.


--
Martin Michlmayr
https://www.cyrius.com/

Scott Carpenter

unread,
Jun 4, 2023, 12:06:47 PM6/4/23
to Ledger
Thanks, Martin. And thanks for all the work you do with maintaining things and managing these releases!

Scott

Antonio MCh

unread,
Nov 20, 2023, 8:19:16 PM11/20/23
to Ledger
  Hello! I'm having a similar issue, or at least the error message is the same:  

  I'm trying to add a commodity like this:

commodity JPY
  format 1,234. JPY

  Note that I have a dot '.' to indicate the commodity does not uses decimals. This is recommended by hledger, but when I try it in ledger (Ledger 3.3.2-20230330) I get the error:
"Error: commodity directive symbol JPY and format directive symbol  should be the same"

  Is that expected?

Thank you!

Antonio M.

Antonio MCh

unread,
Nov 20, 2023, 8:19:16 PM11/20/23
to Ledger
  Hi everyone! I think I'm having the same/similar issue.

  I try to declare the following commodity:

commodity JPY
  format 1,234. JPY

  Note that I include a dot at the end of the amount, this is to indicate the commodity does not uses decimals. This is compatible with hledger, but with ledger, I get the following error:
"Error: commodity directive symbol JPY and format directive symbol  should be the same"

  Is this behavior expected?

Regards

Antonio M.

Martin Michlmayr

unread,
Nov 20, 2023, 9:50:49 PM11/20/23
to ledge...@googlegroups.com
* Antonio MCh <usa....@gmail.com> [2023-11-20 15:35]:
> commodity JPY
> format 1,234. JPY
>
> Note that I have a dot '.' to indicate the commodity does not uses
> decimals. This is recommended by hledger, but when I try it in ledger
> (Ledger 3.3.2-20230330) I get the error:

hledger and ledger are incompatible in several ways. 1,234. is not a
valid number in ledger.

Antonio MCh

unread,
Nov 20, 2023, 10:57:22 PM11/20/23
to Ledger
I tested the commodity declaration in Ledger 3.2.1-20200518, and there it is valid, just wondering if there was a reason to stop supporting that format.

Martin Michlmayr

unread,
Nov 20, 2023, 11:07:26 PM11/20/23
to ledge...@googlegroups.com
There was a bug in earlier version that the format info in commodity
directives were not properly validated.

1,234. is not a valid number in ledger.

Just try this:

2023-01-01 * "Test"
Assets:Investments 1,100. GBP
Assets:Cash -1,100.00 GBP

Related bug not the same:
https://github.com/ledger/ledger/issues/2095
https://github.com/ledger/ledger/issues/1990

Martin


* Antonio MCh <usa....@gmail.com> [2023-11-20 19:57]:
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Ledger" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/6801b1ac-32b1-4a8f-8f24-3139cbb64c8an%40googlegroups.com.

Antonio MCh

unread,
Nov 20, 2023, 11:23:02 PM11/20/23
to Ledger
OK, understand. When the bug was present, I was able to have the same files and run either ledger or hledger depending on the need, I guess I will have to find a way to make them both work together again.

Thanks Martin for your time and help.

Antonio M.
Reply all
Reply to author
Forward
0 new messages