bkettle / message-book

make a book from imessages
303 stars 11 forks source link

failed to generate message: MissingData #1

Closed araujoalexandre closed 6 months ago

araujoalexandre commented 6 months ago

Dear Ben!

Thanks for this project, it looks great! I just tried to run it on a backup of my iPhone and got the following error message:

➜  message-book git:(main) ✗ cargo run -- -i ./backup XXXXXXXXXX'
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/message-book -i ./backup XXXXXXXXXX`
Found chat Chat { rowid: 996, chat_identifier: "XXXXXXXXXX", service_name: Some("SMS"), display_name: Some("") }
Found chat Chat { rowid: 997, chat_identifier: "XXXXXXXXXX", service_name: Some("iMessage"), display_name: Some("") }
Starting chapter ch-2015-10
Starting chapter ch-2015-11
Starting chapter ch-2015-12
Starting chapter ch-2016-01
Starting chapter ch-2016-02
thread 'main' panicked at src/main.rs:137:27:
failed to generate message: MissingData
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::expect
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1030:23
   4: message_book::iter_messages
             at ./src/main.rs:137:9
   5: message_book::main
             at ./src/main.rs:179:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Any idea how to fix it?

Thank you Best Alexandre

jdmcd commented 6 months ago

I have the same problem but using the Mac database, so doesn't seem to be related to iOS vs. Mac backups

ReagentX commented 6 months ago

This happens because the message is missing attributedBody data:

https://github.com/ReagentX/imessage-exporter/blob/2dc3d034bd5e64eb04306c167418989e2dac7651/imessage-database/src/tables/messages.rs#L353

It crashes because that call in this crate uses .expect(), which panics if the Err variant is returned:

https://github.com/bkettle/message-book/blob/b29806662794dc8c5460d59b37a4624f1d83b239/src/main.rs#L137

The issue can be remediated by not using expect() here and using a different method that doesn't crash.

bkettle commented 6 months ago

Thanks for the PR, and @ReagentX for the diagnosis! This should be fixed.