ivan-lednev / obsidian-task-archiver

Archive completed tasks in your Obsidian vault (plus other org-mode-like features)
MIT License
109 stars 12 forks source link

Archiver not working #6

Closed kmaustral closed 2 years ago

kmaustral commented 2 years ago

This plugin used to work fine, but it stopped working with the update. I've tried it in Preview and Edit mode.

These are my options. image

ivan-lednev commented 2 years ago

Hello, @kmaustral, Thank you for raising the issue! Could you share an example of a file that doesn't work with the archiver? I copied your config, tried archiving a couple of tasks, and here is what I've got: image

Also, please check the developer console by pressing Ctrl + Shift + I and selecting the Console tab, do you see any error messages there? If so, it would be helpful if you attached those.

RGNagel commented 2 years ago

Hello @ivan-lednev . First of all, thank you for the work, this is a great extension idea. I used to use org-mode a lot in the past.

Today I tried to use this extension and it didn't work. After executing the command "Archive tasks in this file" in a simple file containing some checkboxes, the console throws the following:

Uncaught (in promise) TypeError: Cannot read property 'append' of undefined
    at BlockParser.buildTree (eval at <anonymous> (app.js:1), <anonymous>:135:25)
    at BlockParser.parse (eval at <anonymous> (app.js:1), <anonymous>:122:14)
    at eval (eval at <anonymous> (app.js:1), <anonymous>:249:80)
    at Array.map (<anonymous>)
    at SectionParser.parseBlocksInSections (eval at <anonymous> (app.js:1), <anonymous>:248:20)
    at SectionParser.parse (eval at <anonymous> (app.js:1), <anonymous>:224:35)
    at Archiver.archiveTasksToSeparateFile (eval at <anonymous> (app.js:1), <anonymous>:304:43)
    at ObsidianTaskArchiver.eval (eval at <anonymous> (app.js:1), <anonymous>:463:48)
    at Generator.next (<anonymous>)
    at fulfilled (eval at <anonymous> (app.js:1), <anonymous>:28:58)

I will take a look at the code to see if I can fix the problem. Thanks again.

ernstnaezer commented 2 years ago

Hi, I had the same issue, and I think it has something todo with copying the example and the pre-fix for task details.

The tab in front of the task (sub) details is copied as 4 spaces and that crashes the plugin. I've replaced the ____ (4 spaces) before the details with a proper tab and the plugin runs.

Looking at BlockParser.ts, it seems the regex to match line items either accepts 2 spaces or a tab. Perhaps an easy fix is to make this a range of spaces.

https://github.com/ivan-lednev/obsidian-task-archiver/blob/f06d7bc5a5d5e201f3fd383c8eb89b3b4f26aa3b/src/parser/BlockParser.ts#L9

Hope this helps

adamhl8 commented 2 years ago

I can confirm what @ernstnaezer said. If you change the regex to take 2 to 4 spaces the plugin runs fine. e.g. {2,4}:

/^(?<indentation>(?: {2,4}|\t)*)(?<listMarker>[-*]|\d+\.)\s/
ivan-lednev commented 2 years ago

Hello, @ernstnaezer

Thank you for your input! Could you please provide a markdown fragment that crashed the plugin? I've tried reproducing the issue with different combinations of tabs & spaces, but no luck so far.

Thanks!

ivan-lednev commented 2 years ago

Since there hasn't been any activity recently, looks like the issue got fixed when some other refactoring happened. Closing.

tumber43 commented 1 year ago

RANGE ERROR: I have a Task note and when I run the plugin to move the completed tasks to a header on the same page or a different note altogether... it removes the tasks but they do not move to the header or the new note, they appear to simply be deleted. I'm definitely triggering the move and not the delete command. I do receive an error: "RangeError Invalid position -1 in document" with a length parameter listed. It is a complex Task note with a recurring task and about a page and a half long. Thoughts?

UPDATE: I experimented with simplifying the Task note, but the only way I could get the error to go away was to remove all existing tasks and then create brand new tasks. When I did that and triggered the Archive Tasks, it moved the completed tasks to the Header section properly and did not throw the error. The test Tasks were simple and didn't have indented subtasks or recurrence. Is that the issue?

Weirdly, there is nothing in the Console when the error occurs.