insanum / sncli

Simplenote CLI
MIT License
396 stars 34 forks source link

Error on creating a note. #20

Closed DiagonalArg closed 7 years ago

DiagonalArg commented 9 years ago

I'm having an error now on creating my first note. This is on ubuntu 12.04. I set cfg_editor = vi (which is vim-tiny). I also installed urwid with pip install urwid as discussed in #19. Version now is:

> pip --version urwid
pip 1.0 from /usr/lib/python2.7/dist-packages (python 2.7)

When I use "C" to create a note, all seems well util I save the note using :wq, which is what I assume I should do when I want to return out of vim into the sncli interface, correct? The error produced (notice the "t" in "traceback" is missing in the output, that's not my copy/paste error) is:

raceback (most recent call last): when manual pages are not available.
  File "/usr/local/bin/sncli", line 33, in <module>
    sncli.main(sys.argv[1:])
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 1200, in main
    sncli(sync).gui(key)D] [COMMAND_ARGS]
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 1016, in gui
    self.sncli_loop.run()
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 278, in run
    self._run()               - verbose output
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 375, in _run
    self.event_loop.run()     - search string is a regular expression
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 678, in run
    self._loop()title=<title> - title of note for create (cli mode)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 715, in _loop
    self._watch_files[fd]()
  File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 392, in <lambda>
    event_loop, callback, self.get_available_raw_input())the server
  File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 492, in parse_input
    callback(processed, processed_codes)es (refined with search string)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 399, in _update
    self.process_input(keys)  - dump a note (specified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/urwid/main_loop.py", line 499, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)ified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 612, in gui_frame_keypress
    self.gui_update_view()>   - markdown/unmarkdown a note (specified by <key>)
  File "/usr/local/lib/python2.7/dist-packages/simplenote_cli/sncli.py", line 265, in gui_update_view
    cur_key = self.view_titles.note_list[self.view_titles.focus_position].note['key']
KeyError: 'key' 

Is this another problem with an old version of urwid?

shawnaxsom commented 9 years ago

Hi Diagonal,

My wife had our first child, so understandably I won't be able to get to this too quickly. I did look into the error message earlier. I don't think it would be related to URWID. At this location in the code, it is trying to get the ID of the note you created, so it can then use that ID when telling it which note to selected when displaying the main list of notes again.

You are correct that you should just have to :wq to save the note. I don't think you did anything wrong.

Is there anything special about your situation? For example, do you have notes already existing in this SimpleNote account?

I'm not sure where that 'key' is supposed to get set. notes_db.create_note() will create the note object, but it doesn't set a key value at that time.

Did the note get saved to SimpleNote successfully, if you check on the website for it? Were you working online or offline when you made the note? It is likely that the key is given to the note by SimpleNote's API, but I'm not sure.

DiagonalArg commented 9 years ago

Congratulations Shawn! :)

I do have two notes in the simplenote account, the "thank you for signing up" note and a test note that I created there. Regardless, I am running using sncli -n. While I do have the credentials for the simplenote account in the .snclirc, but I'm assuming that the -n means that whether it's saved or not and the contents of that account is irrelevant. I have only one note visible in the sncli interface, another test note, and since I always run with -n that is not stored online.

... Ok, so I cleared out the simplenote online account, and ran without -n. Now it's working.

... I ran again with -n and it also works!

Odd bug, though....

You go get some sleep now, ok? :)

samuelallan72 commented 8 years ago

This is definitely still an issue. Steps to reproduce:

  1. run sncli -n (so it doesn't try syncing)
  2. create a new note
  3. try to view the note

The problem is that before it has synced to the server, there is no "key" key set in the note object. This could probably be fixed with some refactoring or using a "localkey" key as is used in other places.

casutherland commented 8 years ago

Update: I can't duplicate the below issue at this time. Chalking it up to possible network connectivity gremlins. Will try to capture the log next time, if this occurs again. Regardless, whether in the case of intermittent/low fidelity connections, or when using -n forced no-sync mode, there should probably be a graceful degradation mode (e.g., "localkey").

I started experiencing this issue anytime I create a new note with sncli, even when my machine is online and sync is /not/ disabled with the -n option. (Although, perhaps the "key" creation operations are just timing out due to a slow connection?)

In the past, I have typically created new notes with nvALT and just used sncli to update notes. So, I'm not sure if this error was recently (re)introduced, or if it has always existed in my environment.

Steps to reproduce:

  1. run sncli
  2. create a note
  3. try to view the note index / "list" view
  4. the "KeyError" trace is partially displayed, overlapping the note index / "list" view (corrupt ui)
  5. try to view the note
  6. sncli crashes with the traceback below
Traceback (most recent call last):
  File "./sncli", line 33, in 
    sncli.main(sys.argv[1:])
  File "/home/myusername/Workspaces/sncli/simplenote_cli/sncli.py", line 1207, in main
    sncli(sync, verbose, config).gui(key)
  File "/home/myusername/Workspaces/sncli/simplenote_cli/sncli.py", line 1019, in gui
    self.sncli_loop.run()
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 278, in run
    self._run()
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 376, in _run
    self.event_loop.run()
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 682, in run
    self._loop()
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 719, in _loop
    self._watch_files[fd]()
  File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 393, in 
    event_loop, callback, self.get_available_raw_input())
  File "/usr/local/lib/python3.4/dist-packages/urwid/raw_display.py", line 493, in parse_input
    callback(processed, processed_codes)
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 403, in _update
    self.process_input(keys)
  File "/usr/local/lib/python3.4/dist-packages/urwid/main_loop.py", line 503, in process_input
    k = self._topmost_widget.keypress(self.screen_size, k)
  File "/home/myusername/Workspaces/sncli/simplenote_cli/sncli.py", line 673, in gui_frame_keypress
    lb.note_list[lb.focus_position].note['key'])
KeyError: 'key'
samuelallan72 commented 8 years ago

I've created a new branch (localkeys) to experiment with fixing this issue. The main reason this is happening, is that although a localkey is created to add the note to it's in-memory database, until the note is synced with the server there is no 'key' key in the note data. I'm attempting to add a 'localkey' key to all notes to use internally.

Feel free to test out the localkeys branch, noting that I haven't tested all the functions much yet and shouldn't be considered stable - an error with referencing keys internally could result in notes being lost/overwritten. (use at own risk!)

samuelallan72 commented 8 years ago

localkeys is now merged into master, along with another last-minute fix. This should fix any crashes/errors relating to note keys.

Please let me know if you still get errors to do with this.