wtfaremyinitials / osa-imessage

Send and receive iMessages with nodejs
MIT License
324 stars 54 forks source link

UnhandledPromiseRejectionWarning when sending message #24

Open yunyu opened 6 years ago

yunyu commented 6 years ago

When running this script:

const iMessage = require('osa-imessage');
iMessage.send('number redacted', 'Hello World');

I get this output in the terminal:

This version of macOS (10.11.6) is currently untested with this version of osa-imessage. Proceed with caution.
(node:644) UnhandledPromiseRejectionWarning: Error: Command failed: /usr/bin/osascript -l JavaScript
31:73: syntax error: Error on line 3: SyntaxError: Unexpected token '>' (-2700)

    at ChildProcess.exithandler (child_process.js:275:12)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:567:12)
(node:644) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:644) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code

I am running Node v8.9.4 and OS X 10.11.6.

yunyu commented 6 years ago

To me, this looks like https://github.com/wtfaremyinitials/osa2/blob/master/index.js#L6 outputting ES6, which is presumably not supported by osascript. It looks like changing all the arrow functions to function () (and possibly changing all of the osa() functions to ES5) would fix it.

Alternatively, using the Babel API in osa2 would also fix it: https://github.com/yunyu/osa2/commit/38bdc2cd346836f553891305205499b22751f97d

wtfaremyinitials commented 6 years ago

The module works as-is on macOS 10.13, so I guess ES6 was added to osascript recently. I like the babel solution; if you PR it I'd be more than happy to merge it.