insanum / sncli

Simplenote CLI
MIT License
396 stars 34 forks source link

Crash on launch #99

Closed drewauff closed 3 years ago

drewauff commented 4 years ago

MacOS Catalina iTerm2

error is as follows :

Traceback (most recent call last):
  File "/Users/drewauff/.local/bin/sncli", line 8, in <module>
    sys.exit(main())
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/sncli.py", line 1356, in main
    sncli(sync, verbose, config).gui(key)
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/sncli.py", line 959, in gui
    view_titles.ViewTitles(self.config,
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/view_titles.py", line 18, in __init__
    urwid.SimpleFocusListWalker(self.get_note_titles()))
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/view_titles.py", line 143, in get_note_titles
    lines.append(self.get_note_title(n.note))
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/view_titles.py", line 128, in get_note_title
    return urwid.AttrMap(self.format_title(note),
  File "/Users/drewauff/.local/pipx/venvs/sncli/lib/python3.8/site-packages/simplenote_cli/view_titles.py", line 49, in format_title
    t = time.localtime(float(note['modificationDate']))
KeyError: 'modificationDate'
samuelallan72 commented 4 years ago

@drewauff Thanks for reporting. Would you mind sharing the debug log from when this happens (obviously, redact anything personal/private from it)? Default location is ~/.sncli/sncli.log.

ThisSentenceIsFalse commented 4 years ago

I'm inclined to make a few observations:

Short-term solution: stricter sanitizing and checking at cache initialization. A longer solution as I see it would be to encapsulate the impl. details and usage patterns of a note in its own class, with proper sanitizing done there. I'd be willing to take a shot at it. Could give way to some healthy separation of concerns, code tidying, some tests like the official electron project does.

What's your take on it @swalladge?

samuelallan72 commented 4 years ago

@ThisSentenceIsFalse to be honest, I think if the notes cache (really the notes database; sncli can work without a simplenote server) are edited by anything other than the app's internal operations, then crashing is ok. Raw editing notes is only supposed to be for an escape hatch if one really wishes to do something advanced that the app doesn't support. As with any app, if you mess with the data files outside of the app, then there will likely be consequences; I'm not sure extra sanitization or checking will be productive here.

importing notes does some more substantial checks, for good reasons - in my view, these reasons apply to cache-loading as well

Yes, because importing notes assumes untrusted data - it needs to do a best effort to successfully and safely import data into the internal format. Loading from the database is a trusted operation because it's within the bounds of the application. Yes it can be maliciously/accidentally edited, but so can the RAM that the live app is running in. ¯\_(ツ)_/¯

A longer solution as I see it would be to encapsulate the impl. details and usage patterns of a note in its own class, with proper sanitizing done there. I'd be willing to take a shot at it. Could give way to some healthy separation of concerns, code tidying, some tests like the official electron project does.

This would be awesome! I'm all for adding tests and tidying the code. If you'd like to give it a shot, then please do! :+1:

drewauff commented 3 years ago

I tried deleting..well I renamed the .sncli DIR and now getting this error

2020-11-30 11:04:48,428 [DEBUG] sncli logging initialized 2020-11-30 11:04:48,464 [DEBUG] Starting new HTTPS connection (1): auth.simperium.com:443 2020-11-30 11:04:49,120 [DEBUG] https://auth.simperium.com:443 "POST /1/chalk-bump-f49/authorize/ HTTP/1.1" 401 None 2020-11-30 11:04:49,123 [DEBUG] Auth error: 401 Client Error: UNAUTHORIZED for url: https://auth.simperium.com/1/chalk-bump-f49/authorize/ 2020-11-30 11:04:49,123 [DEBUG] sncli database doesn't exist, forcing full sync... 2020-11-30 11:04:49,123 [DEBUG] Starting full sync 2020-11-30 11:04:49,123 [DEBUG] ERROR: Failed to get note list from server 2020-11-30 11:04:49,123 [DEBUG] Full sync completed 2020-11-30 11:04:50,150 [DEBUG] Sync worker: started 2020-11-30 11:04:50,150 [DEBUG] Starting full sync 2020-11-30 11:04:50,151 [DEBUG] ERROR: Failed to get note list from server 2020-11-30 11:04:50,151 [DEBUG] Full sync completed 2020-11-30 11:05:05,156 [DEBUG] Starting full sync 2020-11-30 11:05:05,156 [DEBUG] ERROR: Failed to get note list from server 2020-11-30 11:05:05,157 [DEBUG] Full sync completed 2020-11-30 11:05:21,237 [DEBUG] sncli logging initialized 2020-11-30 11:05:21,251 [DEBUG] Starting new HTTPS connection (1): auth.simperium.com:443 2020-11-30 11:05:21,885 [DEBUG] https://auth.simperium.com:443 "POST /1/chalk-bump-f49/authorize/ HTTP/1.1" 401 None 2020-11-30 11:05:21,888 [DEBUG] Auth error: 401 Client Error: UNAUTHORIZED for url: https://auth.simperium.com/1/chalk-bump-f49/authorize/ 2020-11-30 11:05:22,901 [DEBUG] Sync worker: started 2020-11-30 11:05:22,901 [DEBUG] Starting full sync 2020-11-30 11:05:22,902 [DEBUG] ERROR: Failed to get note list from server 2020-11-30 11:05:22,902 [DEBUG] Full sync completed

samuelallan72 commented 3 years ago

@drewauff that looks like your user credentials are incorrect. Could you verify and recheck?

drewauff commented 3 years ago

OMG Works now, don't know what was tripping it previously, that's why i decided to uninstall and rename the .sncli dir.

Awesome, thank you for all your help..just noticed your a fellow Aussie lol, explains the quick response.

Thanks again and good to see this isn't dead.

samuelallan72 commented 3 years ago

@drewauff :+1: :+1:

samuelallan72 commented 3 years ago

I'll close this since the issue has resolved itself. Feel free to reopen or open a new issue if it comes back, and we can investigate it further. :)