threeplanetssoftware / apple_cloud_notes_parser

Parser for Apple Notes data stored on the Cloud as seen on Apple handsets
MIT License
412 stars 26 forks source link

`nil` error during HTML generation #41

Closed huyz closed 2 years ago

huyz commented 2 years ago

(Follow-up to unrelated #40)

I'm getting a crash on one of my notes during HTML generation:

Created a new AppleBackup from Mac backup: /Users/huyz/Library/Group Containers/group.com.apple.notes
Guessed Notes Version: 15
Apple Decrypter: Attempting to decrypt objects without a password list set, check the -w option for more success
Updated AppleNoteStore object with 167 AppleNotes in 19 folders belonging to 1 accounts.
Adding the ZICNOTEDATA.ZPLAINTEXT and ZICNOTEDATA.ZDECOMPRESSEDDATA columns, this takes a few seconds
/Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:589:in `+': no implicit conversion of nil into String (TypeError)
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:589:in `block in generate_html_text'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:562:in `each'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:562:in `each_with_index'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:562:in `generate_html_text'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNote.rb:527:in `generate_html'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNoteStore.rb:742:in `block in generate_html'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNoteStore.rb:740:in `each'
    from /Users/huyz/git/apple_cloud_notes_parser/lib/AppleNoteStore.rb:740:in `generate_html'
    from notes_cloud_ripper.rb:178:in `block (2 levels) in <main>'
    from notes_cloud_ripper.rb:177:in `open'
    from notes_cloud_ripper.rb:177:in `block in <main>'
    from notes_cloud_ripper.rb:171:in `each'
    from notes_cloud_ripper.rb:171:in `<main>'

Here, for the line

          html += @embedded_objects[embedded_object_index].generate_html# + "\n"

embedded_object_index is 0 and @embedded_objects looks like: screenshot 2022-08-06T035407Z

Strange to have some nils in there.

I'm in the debugger if you want me to check the state at specific lines.

threeplanetssoftware commented 2 years ago

This one is more straight forward to understand where it comes from. The to_s function is simply returning @alt_text for the AppleNotesEmbeddedInlineHashtag. That is set immediately from the Apple Note, using the ZICCLOUDSYNCINGOBJECT.ZALTTEXT column:

https://github.com/threeplanetssoftware/apple_cloud_notes_parser/blob/c22a67adc5cc2df71983995a47c833e5c048b340/lib/AppleNote.rb#L185-L191

However, I don't have good test data that shows this behavior. Can you provide more information about the note this came from? Similar to #40, can you provide the debug_log.txt lines for this note? Is there anything noteworthy (no pun intended) about this note (was it deleted? do you still see it in notes?). Do you actually have a hashtag in the note still , or might it have been deleted? If there is a hashtag, is there text on it, or is it somehow blank?

Appreciate the help. Most of my hashtag test generation was on my mac test device, so I'm pretty confident the platform isn't the issue on this one.

huyz commented 2 years ago

Yes, I found that this note was yet another quasi-deleted version of the same note content I mentioned in https://github.com/threeplanetssoftware/apple_cloud_notes_parser/issues/40#issuecomment-1202930301 , except it has note ID 912 instead of ID 903 (my good, recent note which does show up in Apple Notes has ID 4183--a much larger ID number because I've duplicated and deleted the same note multiple times recently, both before and after working with apple_cloud_notes_parser, in a partially-successful attempt to garbage-collect attachments).

If I skip processing of this note ID 912, I run into another case of a nil hashtag on yet another quasi-deleted note (note ID 1137) that doesn't show up in my searches or Recently Deleted folder (the good, recent version of that note has ID 1390).

And now, thankfully, the app runs to completion. And I can finally look at the HTML web page generated.


It's so nice to be able to look at all my notes content on a web page! I have lost note content several times because iCloud Notes has no concept of versioning. I am much relieved that I finally have a way to back up and version the content. I'll probably git commit

This could form the basis for a great Apple Notes -> HTML -> Markdown conversion tool.

Thank you so much for this project!