Python "Traceback (most recent call last)" on Syntax Error

128 views
Skip to first unread message

jfs...@gmail.com

unread,
Jan 9, 2017, 2:07:14 AM1/9/17
to Beancount
Hi Martin,

Happy New Year!

I wasn't sure if this should be entered as an issue, thought I would let you decide.  I am working on importing my credit card statements by running bean-extract and saving to a file, copying the credit card opening statement and expenses to the new file, and then adding the other half of the transactions.  When I ran bean-check on the completed file, I got the following error.  I figured I must have missed something in the new file, so I copied all the completed transactions to my normal beancount file, which had passed bean-check.  It then incurred the same error.  By process of elimination, I found I had missed putting the 'USD' after a transaction.  After adding the 'USD', bean-check worked fine.  Your code seems to handle most other errors, so I didn't think the Traceback was your way of notifying of a syntax error.

Jonathan


Enter code here...JFSMini1:Beancount$ bean-check jfsgmsbgn.bean

Traceback (most recent call last):

  File "/usr/local/bin/bean-check", line 2, in <module>

    from beancount.scripts.check import main; main()

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/scripts/check.py", line 39, in main

    extra_validations=validation.HARDCORE_VALIDATIONS)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/loader.py", line 87, in load_file

    extra_validations, encoding)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/loader.py", line 200, in wrapped

    result = function(toplevel_filename, *args, **kw)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/loader.py", line 219, in _load_file

    return _load([(filename, True)], *args, **kw)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/loader.py", line 460, in _load

    extra_validations)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/ops/validation.py", line 395, in validate

    new_errors = validation_function(entries, options_map)

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/ops/validation.py", line 348, in validate_check_transaction_balances

    "Transaction does not balance: {}".format(residual),

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/core/inventory.py", line 104, in __str__

    return self.to_string()

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/core/inventory.py", line 96, in to_string

    ', '.join(pos.to_string(dformat) for pos in sorted(self)))

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/core/position.py", line 228, in __lt__

    return self.sortkey() < other.sortkey()

  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beancount/core/position.py", line 210, in sortkey

    order_units = CURRENCY_ORDER.get(currency, NCURRENCIES + len(currency))

TypeError: object of type 'type' has no len()


Martin Blais

unread,
Jan 9, 2017, 4:41:48 AM1/9/17
to Beancount
This looks like a bug. This should not happen. Beancount should never raise an uncaught exception.

Could you copy your input, isolate the offending transaction, and wittle it down to the smallest file that will reproduce the problem?  Replace numbers and other private things if needed. I'd appreciate, would save me time. You can email to me directly if you're concerned about privacy.

Thanks,





--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/df2169e7-a716-496d-9eb8-d38ea670c4da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jfs...@gmail.com

unread,
Jan 10, 2017, 1:54:32 AM1/10/17
to Beancount
Hi Martin,

I thought it might be a bug because you seem to be a too good and careful coder to let an uncaught exception through.  Here is the simplest file that causes an exception for me.  It is the original transaction that caused it.  Nothing sensitive there.  Besides, Google already knows about it ;>)  Just add USD to the two Expenses lines and everything is fine.

Jonathan

;; -*- mode: org; mode: beancount; coding: utf-8; -*-
**** /Users/jonathan/Documents/Beancount/documents/Expenses/Fidelity/2016-12-28FidelityVisa.csv

** Fidelity Investments

1982-01-01 open Liabilities:US:FidelityVisa                    USD



2016-11-16 * "BJ WHOLESALE #0209 HUDSON" | "Groceries, Sonicare 4Pk"
  txndate: 2016-11-15
  Liabilities:US:FidelityVisa  -77.26 USD
  Expenses:PersonalCare         42.49
  Expenses:Food:Groceries       34.77

* Expenses
1957-06-25 open Expenses:Food:Groceries
1957-06-25 open Expenses:PersonalCare
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

Martin Blais

unread,
Jan 10, 2017, 2:53:03 AM1/10/17
to Beancount
On Mon, Jan 9, 2017 at 8:54 PM, <jfs...@gmail.com> wrote:
Hi Martin,

I thought it might be a bug because you seem to be a too good and careful coder to let an uncaught exception through.  

Oh I make a lot of mistakes, don't worry.

 
Here is the simplest file that causes an exception for me.  It is the original transaction that caused it.  Nothing sensitive there.  Besides, Google already knows about it ;>)  Just add USD to the two Expenses lines and everything is fine.

What version are you using?
Here's what the latest on the default branch does for me, which looks appropriate:


bean-check test.beancount
/tmp/test.beancount:13:      Failed to categorize posting 1

   2016-11-16 * "BJ WHOLESALE #0209 HUDSON" "Groceries, Sonicare 4Pk"
     txndate: 2016-11-15
     Liabilities:US:FidelityVisa                               -77.26 USD
     Expenses:PersonalCare        42.49 <class 'beancount.core.number.MISSING'>
     Expenses:Food:Groceries      34.77 <class 'beancount.core.number.MISSING'>


/tmp/test.beancount:14:      Failed to categorize posting 2

   2016-11-16 * "BJ WHOLESALE #0209 HUDSON" "Groceries, Sonicare 4Pk"
     txndate: 2016-11-15
     Liabilities:US:FidelityVisa                               -77.26 USD
     Expenses:PersonalCare        42.49 <class 'beancount.core.number.MISSING'>
     Expenses:Food:Groceries      34.77 <class 'beancount.core.number.MISSING'>



 
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Jonathan Salles

unread,
Jan 11, 2017, 1:19:19 AM1/11/17
to bean...@googlegroups.com
Hi Martin,

I didn't see how to get the version, I tried -h on bean-extract and
bean-check, but no version. In __init__.py in beancount, it states
"This is v2, a complete rewrite of Beancount v1, simplified and
improved
drastically."

Apologies if I missed something simple.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Beancount" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/beancount/VAUQSb8pa4g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> beancount+...@googlegroups.com.
> To post to this group, send email to bean...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/CAK21%2BhOOGe6M-V0R%3DKWZT%2BKZsoPAf0JLRM%2BJfTBxLe%3DS0NfFVA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages