Repository: rotki/rotki

Issue:
Exception at makerdao vaults processing
## Problem Definition


Running on my uniswap test account PnL report for 2020 with v1.120.0 I got an exception. Need to investigate further what this is and fix it

```
[08/08/2021 19:59:41 CEST] ERROR rotkehlchen.api.rest: Greenlet for task 11 dies with exception: invalid literal for int() with base 10: ''.
Exception Name: <class 'ValueError'>
Exception Info: invalid literal for int() with base 10: ''
Traceback:
   File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "rotkehlchen/api/rest.py", line 274, in _do_query_async
  File "rotkehlchen/api/rest.py", line 1561, in _process_history
  File "rotkehlchen/rotkehlchen.py", line 594, in process_history
  File "rotkehlchen/history/events.py", line 268, in get_history
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 749, in get_history_events
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 731, in get_vault_details
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 519, in _query_vault_details
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 150, in _shift_num_right_by
```

## Task

Fix it
Exception at makerdao vaults processing
## Problem Definition


Running on my uniswap test account PnL report for 2020 with v1.120.0 I got an exception. Need to investigate further what this is and fix it

```
[08/08/2021 19:59:41 CEST] ERROR rotkehlchen.api.rest: Greenlet for task 11 dies with exception: invalid literal for int() with base 10: ''.
Exception Name: <class 'ValueError'>
Exception Info: invalid literal for int() with base 10: ''
Traceback:
   File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "rotkehlchen/api/rest.py", line 274, in _do_query_async
  File "rotkehlchen/api/rest.py", line 1561, in _process_history
  File "rotkehlchen/rotkehlchen.py", line 594, in process_history
  File "rotkehlchen/history/events.py", line 268, in get_history
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 749, in get_history_events
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 731, in get_vault_details
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 519, in _query_vault_details
  File "rotkehlchen/chain/ethereum/modules/makerdao/vaults.py", line 150, in _shift_num_right_by
```

## Task

Fix it


Discussion:
Will have a look at this one. Was not easy to reproduce but saw it happen once.
Will have a look at this one. Was not easy to reproduce but saw it happen once.

Resolving patch:
diff --git a/rotkehlchen/chain/ethereum/modules/makerdao/vaults.py b/rotkehlchen/chain/ethereum/modules/makerdao/vaults.py
--- a/rotkehlchen/chain/ethereum/modules/makerdao/vaults.py
+++ b/rotkehlchen/chain/ethereum/modules/makerdao/vaults.py
@@ -147,7 +147,15 @@ def _shift_num_right_by(num: int, digits: int) -> int:
     6150000000000000000000000000000000000000000000000 // 1e27
     6.149999999999999e+21   <--- wrong
     """
-    return int(str(num)[:-digits])
+    try:
+        return int(str(num)[:-digits])
+    except ValueError:
+        # this can happen if num is 0, in which case the shifting code above will raise
+        # https://github.com/rotki/rotki/issues/3310
+        # Also log if it happens for any other reason
+        if num != 0:
+            log.error(f'At makerdao _shift_num_right_by() got unecpected value {num} for num')
+        return 0
 
 
 class VaultEventType(Enum):


Test patch: