carderne / signal-export

Export your Signal chats to markdown files with attachments
Other
436 stars 46 forks source link

Run from commit 20c47 fails on KeyError while building reactions in make_simple() #34

Closed coppolab closed 2 years ago

coppolab commented 2 years ago

Hi,

I just get the following runtime error when running 20c47 (all sensitive data made fake):

File "/Users/pippo/sw/signal-export/./sigexport.py", line 170, in f"{contacts[r['fromId']]['name']}: {r['emoji']}" KeyError: '+393283754636'

From a preliminary analysis, it seems that an attempt is made to access contacts by key from reaction['fromId'] which is actually a telephone number, while it should be an uuid according to contacts structure. This is the reaction printout:

{'emoji': '😮', 'remove': False, 'targetAuthorE164': '+393283754636', 'targetAuthorUuid': '79e85623-4d6e-4de1-9c0c-bcb8596400fb', 'targetTimestamp': 1590281466061, 'timestamp': 1590281632276, 'fromId': '+393283754636', 'fromSync': True}

I attempted to track why a phone number happens to be there, but I gave up at the db query execution.

In case it may be relevant, this is coming from the special "Note to Self" conversation, even though I think it was simply the first one processed.

Thanks for your effort on this excellent project.

Bc.

carderne commented 2 years ago

Have added a try block in 21469253471149a859a1a45ce9cbf63153681258 with some debugging code.

Try re-running and see if any work, or if all the fromIds are phone numbers. Also if you can, print the contacts variable keys and see which of the uuids in what you pasted above match up!

coppolab commented 2 years ago

Analyzing the debugging dump, it seems the issue is entirely time-sensitive, and due to Signal past release changes.

In fact, taking the whole set of ill-formed reactions raising exception and their timestamps, I observe:

After LAST date, everything is working totally fine, and fromId is systematically the right uuid. And, if I recall correctly, reactions were exactly introduced approximately around that FIRST date.

I guess Signal has just been casting wrong reaction data for a few months since introducing them.

As long as the try block remains there, everything is going to work properly since approx August 2020. You may choose either living with that, or totally fix the issue and retrieve the uuid from phone for those cases, which I guess it should be a simple lookup in contacts, plus maybe a stricter regex to check the wrong field is actually a phone number.

Thanks again!

carderne commented 2 years ago

Thanks for figuring it out. Probably just leave it for now!