eprbell / rp2

Privacy-focused, free, open-source cryptocurrency tax calculator for multiple countries: it handles multiple coins/exchanges and computes long/short-term capital gains, cost bases, in/out lot relationships/fractioning, and account balances. It supports FIFO, LIFO, HIFO and it outputs in form 8949 format. It has a programmable plugin architecture
https://pypi.org/project/rp2/
Apache License 2.0
256 stars 42 forks source link

Parameter 'crypto_fee' has zero value #101

Open splix opened 10 months ago

splix commented 10 months ago

rp2_us fails with error:

INFO: Country: us
INFO: Generation Language: en
INFO: Accounting method: fifo
INFO: Configuration file: ../reports/test_crypto_data.ini
INFO: Input file: ../reports/test_crypto_data.ods
INFO: Processing ETH
ERROR: Fatal exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/rp2/rp2_main.py", line 143, in _rp2_main_internal
    input_data: InputData = parse_ods(configuration=configuration, asset=asset, input_file_handle=input_file_handle)
  File "/usr/local/lib/python3.10/site-packages/rp2/ods_parser.py", line 127, in parse_ods
    _create_and_process_transaction(
  File "/usr/local/lib/python3.10/site-packages/rp2/ods_parser.py", line 166, in _create_and_process_transaction
    transaction: AbstractTransaction = _create_transaction(configuration, current_table_type, internal_id, row_values)
  File "/usr/local/lib/python3.10/site-packages/rp2/ods_parser.py", line 286, in _create_transaction
    transaction = OutTransaction(**argument_pack)
  File "/usr/local/lib/python3.10/site-packages/rp2/out_transaction.py", line 60, in __init__
    self.__crypto_fee = configuration.type_check_positive_decimal("crypto_fee", crypto_fee, non_zero=True)
  File "/usr/local/lib/python3.10/site-packages/rp2/configuration.py", line 468, in type_check_positive_decimal
    raise RP2ValueError(f"Parameter '{name}' has zero value")
rp2.rp2_error.RP2ValueError: Parameter 'crypto_fee' has zero value

I've checked the file and it doesn't have any line with zero value, but there are few lines with a very small value. That may be the reason, but anyway it's hard to find out where is the problem with such error message.

I suggest to include the actual string which rp2 failed to parse in the error message. And if it's possible the line number from the file.

eprbell commented 10 months ago

Thanks for reporting. Could you run with debug logs enabled? Logs are stored in the log directory. To generate debug logs, prepend the command line with LOG_LEVEL=DEBUG, e.g.:

LOG_LEVEL=DEBUG rp2_us -o output -p crypto_example_ config/crypto_example.ini input/crypto_example.ods

Then open the log and check the end of it (probably the last line): it should give us clues as to what is happening. Before posting here any personal data please read this and feel free to sanitize your logs to skip sensitive info.

splix commented 10 months ago

Turns out there were a zero value, but for a some reason LibreOffice wasn't able to find it. So it's not a RP2 bug.

So just to improve the situation, maybe it worth adding the line number to the error?

I tried something like that to ods_parser.py:125:

try:
    # Transaction line
    _create_and_process_transaction(
        configuration, row_values, current_table_type, i + 1, artificial_internal_id, unfiltered_transaction_sets, artificial_transaction_list
    )
except RP2Error as exc:
    raise RP2ValueError(f"{asset}({i + 1}): {exc}") from exc

It helped me to find the incorrect line. I see a similar catch in other lines, but not for _create_and_process_transaction call, not sure what is the reason.

eprbell commented 10 months ago

Glad you found the problem. Also what you suggest is a good improvement: can you open a PR? Thanks.