Ver código fonte

Add handling for case when backup has no returned chats.

Rich Infante 7 anos atrás
pai
commit
7cfe535666
2 arquivos alterados com 11 adições e 2 exclusões
  1. 10 1
      tools/index.js
  2. 1 1
      tools/util/iphone_backup.js

+ 10 - 1
tools/index.js

@@ -3,7 +3,7 @@ const inquirer = require('inquirer')
 const chalk = require('chalk')
 
 async function main() {
-
+  try {
   var backups = await backup.availableBackups()
 
   var result = await inquirer.prompt({
@@ -22,6 +22,7 @@ async function main() {
   })
   
   const selectedBackup = backup.iPhoneBackup.fromID(result.backupid)
+  
   const conversations = await selectedBackup.getConversations()
 
   var conversation = await inquirer.prompt({
@@ -43,8 +44,16 @@ async function main() {
     messages.map(el => chalk.gray(el.date ? el.date.toLocaleString() : '') + ' ' + chalk.blue(el.sender + ': ') + el.text)
     .join('\n')
   )
+  } catch(e) {
+    console.log(e)
+  }
 }
 
+process.on('unhandledRejection', (reason, p) => {
+  console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
+  // application specific logging, throwing an error, or other logic here
+})
+
 try {
   main()
 } catch (e) {

+ 1 - 1
tools/util/iphone_backup.js

@@ -50,7 +50,6 @@ class iPhoneBackup {
   getDatabase(fileID) {
     // Get the backup folder
     const base = path.join(process.env.HOME, '/Library/Application Support/MobileSync/Backup/', this.id)
-
     // Return v2 filename
     if (this.status.Version < 3) {
       return new sqlite3.Database(path.join(base, fileID), sqlite3.OPEN_READONLY)
@@ -146,6 +145,7 @@ class iPhoneBackup {
       var messagedb = this.getDatabase(databases.SMS)
 
       messagedb.all('SELECT * FROM chat', async function (err, rows) {
+        rows = rows || []
         for(var el of rows) {
           if (el.properties) el.properties = bplist.parseBuffer(el.properties)[0]
           if (el.properties) {