vonshednob / pter

Manage your todo.txt in a commandline user interface (TUI)
https://vonshednob.cc/pter/
MIT License
102 stars 6 forks source link

Archiving and deleting broken when task creation date is missing #43

Closed andrei-a-papou closed 6 months ago

andrei-a-papou commented 6 months ago

When archiving or deleting, the task remains on screen, no message is printed in the status bar. If you hit the archive or delete shortcut again, pter v3.15.2 crashes with the following error:

[DEBUG] Current key sequence: ('%',)
[DEBUG] Calling archive
[DEBUG] Using archive file ~/.config/pter/archive.txt
[CRITICAL] Pter crashed with exception: list.remove(x): x not in list
  File "/usr/local/lib/python3.11/dist-packages/pter-3.15.2-py3.11.egg/pter/curses.py", line 2941, in run_cursesui
    window.run()
  File "/usr/local/lib/python3.11/dist-packages/cursedspace-1.5.2-py3.11.egg/cursedspace/application.py", line 59, in run
    raise exception
  File "/usr/local/lib/python3.11/dist-packages/cursedspace-1.5.2-py3.11.egg/cursedspace/application.py", line 52, in run
    self.main()
  File "/usr/local/lib/python3.11/dist-packages/pter-3.15.2-py3.11.egg/pter/curses.py", line 1734, in main
    self.functions[fnc]()
  File "/usr/local/lib/python3.11/dist-packages/pter-3.15.2-py3.11.egg/pter/curses.py", line 2650, in do_archive
    success, task = self.modify_task(taskline, _do_delete)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pter-3.15.2-py3.11.egg/pter/curses.py", line 2078, in modify_task
    fnc(task)
  File "/usr/local/lib/python3.11/dist-packages/pter-3.15.2-py3.11.egg/pter/curses.py", line 2647, in _do_delete
    t.todotxt.tasks.remove(t)

~Archiving and deleting work OK in 3.13.0, but not in later releases.~ Nope, also broken.

andrei-a-papou commented 6 months ago

Strange, I can't reproduce it anymore... @vonshednob Can you?

andrei-a-papou commented 6 months ago

OK, figured it out!

abc xyz 123 due:2024-12-12 <- this kind of task will trigger the bug 2023-01-01 abc xyz 123 due:2024-12-12 <- this kind of task will NOT trigger the bug

Missing creation date seems to be the culprit. I have tasks with and without it.

vonshednob commented 6 months ago

Thanks for investigating! I'll see how to fix this

vonshednob commented 6 months ago

I cannot reproduce the issue, but I cannot archive tasks either :sweat_smile: so I'm fixing that bug at least.

I also see how the bug that you describe could be triggered, but I don't understand how pter can get into this type of situation. I'll investigate some more.

vonshednob commented 6 months ago

Ah! I think I understand how this happened. Probably happened every 2nd time you try to archive a task; but the first time it doesn't actually archive it (because that was broken with an update to pytodotxt, I think).

The change is in how pter triggers the detection of a change in the task: task.parse(""), but with a more recent version(?) of pytodotxt parsing an empty string would not cause any change in the description, thus the task appears unchanged → problems.

Anyway, appears to be fixed for both deletion and archiving (not released yet, but the changes are in the codeberg repo).

andrei-a-papou commented 6 months ago

Probably happened every 2nd time you try to archive a task; but the first time it doesn't actually archive it

I think so, yes. Try to archive the first time -- nothing appears to happen. Try to do it a second time -- pter crashes.

but I don't understand how pter can get into this type of situation

I've migrated my todo.txt from another tool and some of my todos had missing creation dates. That may have been a factor.

Thanks for fixing it, I'll test the code soon.

andrei-a-papou commented 6 months ago

Tested, seems to work fine, thank you!