tmo1 / sms-ie

SMS Import / Export is a simple Android app that imports and exports SMS and MMS messages, call logs, and contacts from and to JSON / NDJSON files.
GNU General Public License v3.0
336 stars 39 forks source link

Enhancement: Catch JSON parsing errors during import and show in application #59

Closed xhajt03 closed 1 year ago

xhajt03 commented 1 year ago

Hello, thanks for your application, I managed to import my several thousands text messages from about 14 years of using Nokia phones with Symbian now! Moreover, I like the fact that I can backup my messages using your application as well. However, I'd like to suggest to improve user friendliness of SMS IE by catching JSON parsing errors (and preferably other types of errors as well) and displaying some error message rather than simply crashing / dying. I had to create the import file by translating it to JSON from a CSV file (I created my own simple application running on a PC for that). While doing that, I had to discover and fix some bugs coming from differences in e.g. escaping certain characters in CSV and JSON, etc. However, I had to find these issues in the Android log retrieved using logcat rather than within the application, because the application simply crashed without providing any kind of feedback.

tmo1 commented 1 year ago

Hello, thanks for your application

You're welcome!

I managed to import my several thousands text messages from about 14 years of using Nokia phones with Symbian now!

Wow, you managed to successfully import self-created JSON - that's impressive!

However, I'd like to suggest to improve user friendliness of SMS IE by catching JSON parsing errors (and preferably other types of errors as well) and displaying some error message rather than simply crashing / dying.

This is probably worth doing. When I wrote the app, I wasn't really sure how much error checking to do. I've added some to address bug reports (e.g., #42), but I'm still not really sure how extensive to make these checks. I do agree that not crashing on unparseable JSON is a good idea, and I plan to implement this when I get a chance.

I had to create the import file by translating it to JSON from a CSV file (I created my own simple application running on a PC for that).

I've actually been trying to provide a general solution to this sort of thing with SMS Import / Export's sibling project sms-db. The development of the latter actually predates that of the former by a couple of years, but it has stagnated. I'd like to put some more work into it if / when I get a chance, and eventually get it to export to SMS Import / Export compatible JSON, and possibly to import messages from additional formats, such as CSV.

While doing that, I had to discover and fix some bugs coming from differences in e.g. escaping certain characters in CSV and JSON, etc. However, I had to find these issues in the Android log retrieved using logcat rather than within the application, because the application simply crashed without providing any kind of feedback.

I'll just note that even if / when I add code to the app to catch exceptions thrown by unparseable JSON, I'll probably just have the app show a message that it can't parse the JSON, and refer the user to the logcat for more details - the app UI doesn't seem the right place for reporting the nitty-gritty technical details.

Thank you for reporting your experience and for the suggestion.

xhajt03 commented 1 year ago

The error message raised by the JSON parser as an exception included the line and column number plus the discovered problem, i.e. not really very complicated and/or impossible to display in a UI (probably much easier to handle for a regular user than the procedure for accessing logcat ;-) ), but it's obviously up to you how the application should behave in case of such errors.

Creating the JSON based on the example created by exporting messages using your application wasn't really that difficult (as mentioned previously, I didn't create it manually, but rather created a simple text processing utility for that - I already created dozens of various simple tools for many different purposes in Pascal during the last 30 years or so... ;-) ). In this case, I performed some preprocessing in a spreadsheet (LibreOffice) to transform fields included in the original CSV format created by Nokia Suite to the fields needed for import purposes, so my tool handled only the translation from the modified CSV to JSON. The most challenging part was translation of date and time into the format expected by SMS IE using a spreadsheet formula, especially considering the fact, that I had to find out the used date and time representation by experimenting.

xhajt03 commented 1 year ago

Oops, sorry, I definitely didn't intend to close it...

tmo1 commented 1 year ago

The error message raised by the JSON parser as an exception included the line and column number plus the discovered problem, i.e. not really very complicated and/or impossible to display in a UI (probably much easier to handle for a regular user than the procedure for accessing logcat ;-) ), but it's obviously up to you how the application should behave in case of such errors.

I decided to implement a dialog box that shows the error itself, and directs the user to logcat for more information. I can always reconsider and add more information (e.g., line numbers) to the dialog box.

Creating the JSON based on the example created by exporting messages using your application wasn't really that difficult (as mentioned previously, I didn't create it manually, but rather created a simple text processing utility for that - I already created dozens of various simple tools for many different purposes in Pascal during the last 30 years or so... ;-) ). In this case, I performed some preprocessing in a spreadsheet (LibreOffice) to transform fields included in the original CSV format created by Nokia Suite to the fields needed for import purposes, so my tool handled only the translation from the modified CSV to JSON.

I'm still impressed (and also delighted that someone found the app useful in a way that I hadn't quite anticipated)!

The most challenging part was translation of date and time into the format expected by SMS IE using a spreadsheet formula, especially considering the fact, that I had to find out the used date and time representation by experimenting.

Just to be clear, it's not my format, it's Android's - SMS I/E is just exporting and importing Android's internal date / time representation.

xhajt03 commented 1 year ago

Thanks for the implementation. I'll be happy to test your changes once they're released.

And yes, I understand that the date / time format wasn't your invention. ;-)