obsidian-tasks icon indicating copy to clipboard operation
obsidian-tasks copied to clipboard

Stuck on "Loading Tasks..." due to "Cannot read properties from undefined...Function.getTasksFromFileContent"

Open bramses opened this issue 2 years ago • 7 comments

Expected Behavior

Tasks successfully load into a markdown note using the correct syntax e.g.

not done
heading includes todo/scratchpad

Current behaviour

2022-08-19--08-18-17

Steps to reproduce

Query:

not done
heading includes todo/scratchpad

Which Operating Systems are you using?

  • [ ] Android
  • [X] iPhone/iPad
  • [ ] Linux
  • [X] macOS
  • [ ] Windows

Obsidian Version

0.15.9

Tasks Plugin Version

1.11.1

Checks

  • [X] I have tried it with all other plugins disabled and the error still occurs

Possible solution

I did end up fixing it. Here's how:

  1. I installed tasks locally and reran the uncompiled version
  2. I added the following code:
if (line === undefined) {
	console.log(path + ' path');
	console.error('line is undefined');
	return null;
}
console.log(line);
const regexMatch = line.match(Task.taskRegex);
if (regexMatch === null) {
	return null;
}
  1. From there, I was able to see that the problem path was throwing this error:
2022-08-19--08-14-39
  1. I found the file that was causing the error and cleaned it out, "unstucking" Tasks.

Recommendation: the error surfaced in console wasn't too helpful on its own. A try catch around this line: https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/src/Task.ts#L237

that exposes the arguments of what the offending line is (a stack dump of the arguments: line, path, sectionStart, sectionIndex, precedingHeader) would allow for user debugging without needing to locally install

bramses avatar Aug 19 '22 13:08 bramses

Closing this issue since it is technically solved on my own machine, but I hope this is useful @claremacrae!

bramses avatar Aug 19 '22 13:08 bramses

Thank you very much for logging this.

I'll re-open it for visibility, or we will never seen it to do anything with it.

claremacrae avatar Aug 19 '22 14:08 claremacrae

@bramses Nice debugging and good suggestion! When you say you "cleaned out" the file that was causing Tasks to get stuck, do you have any idea what type of syntax you needed to clean to make the issue go away?

AnnaKornfeldSimpson avatar Aug 19 '22 15:08 AnnaKornfeldSimpson

@AnnaKornfeldSimpson thanks! Basically in my case I have an "read later archive" file of todo links (think online articles I save for later and such), and one of them -- still not sure which one since I only debugged the path was bugging. So I removed [x] from all of the archived elements and Tasks started working again

bramses avatar Aug 19 '22 16:08 bramses

Thank you very much indeed. Just noting some possible things that come to. mind:

  • the call-stack/traceback shows the error was in variable match being undefined in a function fromLine() called from Cache.getTasksFromFileContent()
    • Could there be a problem with a regex that doesn't work with unicode characters?
  • I am suspicious Cache.indexFile() using metadataCache.getFileCache(file) and its possibility of reading out-of-date file context.
    • What if a file is updated via sync whilst its contents are being read?

@bramses if it happens again, or if you can restore the offending file from backup, it would be really helpful to know what the line or character was that caused the problem please. That way I could fix the underlying issue.

claremacrae avatar Aug 20 '22 05:08 claremacrae

Could there be a problem with a regex that doesn't work with unicode characters?

Possibly! These links come from all over so I wouldn't be surprised if a few had weird Unicode symbols.

What if a file is updated via sync whilst its contents are being read?

I use sync and git so one of them might've put a file into a weird state 😅

if it happens again, or if you can restore the offending file from backup, it would be really helpful to know what the line or character was that caused the problem please. That way I could fix the underlying issue.

I'll let you know if it pops up again! FWIW the line itself was undefined (which is why I added the conditional) so perhaps its not getting set somewhere upstream?

bramses avatar Aug 20 '22 15:08 bramses

I will be tracking this issue in #829.

claremacrae avatar Sep 20 '22 08:09 claremacrae