Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOS !! macos Cannot read property 'note_count' of undefined #2079

Closed
ghost opened this issue Nov 12, 2019 · 8 comments
Closed

SOS !! macos Cannot read property 'note_count' of undefined #2079

ghost opened this issue Nov 12, 2019 · 8 comments
Labels
bug It's a bug

Comments

@ghost
Copy link

ghost commented Nov 12, 2019

Fatal error:

Cannot read property 'note_count' of undefined

TypeError: Cannot read property 'note_count' of undefined
at noteCounts.forEach (/Applications/Joplin.app/Contents/Resources/app/lib/models/Folder.js:124:33)
at Array.forEach ()
at Function.addNoteCounts (/Applications/Joplin.app/Contents/Resources/app/lib/models/Folder.js:120:14)
at process._tickCallback (internal/process/next_tick.js:68:7)

@ghost ghost added the bug It's a bug label Nov 12, 2019
@ghost ghost changed the title SOS !! Cannot read property 'note_count' of undefined SOS !! macos Cannot read property 'note_count' of undefined Nov 12, 2019
@laurent22
Copy link
Owner

@erdody, it happens on this line:

folder.note_count = (folder.note_count || 0) + noteCount.note_count;

Any idea what could be the issue? I think I'll hot-fix it later today by just checking if folder is undefined and skip it, if it is, but it would be good to understand what's causing this.

@genneko
Copy link
Contributor

genneko commented Nov 12, 2019

I encountered exactly the same problem after upgrading to v1.0.173.
My temporary solution is as follows. I'm not sure about its root cause but there's similar checks all around in the file.

diff --git a/ReactNativeClient/lib/models/Folder.js b/ReactNativeClient/lib/models/Folder.js
index f994224a..5f9b6c50 100644
--- a/ReactNativeClient/lib/models/Folder.js
+++ b/ReactNativeClient/lib/models/Folder.js
@@ -121,6 +121,7 @@ class Folder extends BaseItem {
 			let parentId = noteCount.folder_id;
 			do {
 				let folder = foldersById[parentId];
+				if(!folder) break;
 				folder.note_count = (folder.note_count || 0) + noteCount.note_count;
 				parentId = folder.parent_id;
 			} while (parentId);

@laurent22
Copy link
Owner

@genneko, @snailman, was the Conflict notebooks in the sidebar when you got this error?

@genneko
Copy link
Contributor

genneko commented Nov 12, 2019

@laurent22
No. I suspected that but I didn't have the folder. I also quickly queried the database for notes associated with non-existing folder but couldn't find ones.

@genneko
Copy link
Contributor

genneko commented Nov 12, 2019

Correction. Actually I couldn't check the sidebar because when I got the error, the app exited right after closing the dialog box. I only examined folders and notes through sqlite3 command afterwards. Sorry for my confusion. That was a few hours before and now I don't have access to the system where the error occurred.

@laurent22
Copy link
Owner

Come to think of it, it would also happen while syncing, when a notebook is downloaded but its parent hasn't been downloaded yet. So indeed the fix will simply be to check if the folder exists before proceeding.

@ghost
Copy link
Author

ghost commented Nov 12, 2019

I changed Synchronisation from one drive to File system and then click the Synchronise button and the same time delete some files in the local directory ;close the app immediately , I got the error when restart the app.

@erdody
Copy link
Contributor

erdody commented Nov 12, 2019

@laurent22 as mentioned, the most likely explanation is a reference (in the folders table) to a non-existing folder id. If we used a view, as we do with tags, that would have been avoided, at the cost of always querying for counts, even if the feature is not enabled.

@lock lock bot locked and limited conversation to collaborators Nov 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug It's a bug
Projects
None yet
Development

No branches or pull requests

3 participants