kusold / todoist-habitrpg

One way sync from Todoist -> HabitRPG
120 stars 14 forks source link

TypeError: Cannot read property 'body' of undefined in apiv3.js #47

Open ajfclark opened 7 years ago

ajfclark commented 7 years ago

Last night my cron job failed with:

/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:189
  if(apiVersion === 'v2' && res.body) {
                               ^

TypeError: Cannot read property 'body' of undefined
    at formatResponse (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:189:32)
    at /usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:61:7
    at Request.callback (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/node_modules/superagent/lib/node/index.js:660:30)
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/node_modules/superagent/lib/node/index.js:628:10)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at TLSSocket.socketErrorListener (_http_client.js:256:9)
    at emitOne (events.js:77:13)
    at TLSSocket.emit (events.js:169:7)
    at connectErrorNT (net.js:997:8)

Trying to rerun the sync fails with:

/usr/local/lib/node_modules/todoist-habitrpg/habitSync.js:218
        if(res.body.type == "daily") {
                   ^

TypeError: Cannot read property 'type' of undefined
    at /usr/local/lib/node_modules/todoist-habitrpg/habitSync.js:218:20
    at fn (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/async/lib/async.js:638:34)
    at Immediate._onImmediate (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/async/lib/async.js:554:34)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Previous syncs have worked fine.

ajfclark commented 7 years ago

This cropped up again when I renamed a label in todoist trying to get the attributes to sync across correctly.

eringiglio commented 7 years ago

It's a persistent issue for me, too, especially if I accidentally complete a task in habitica without completing it in todoist. Unfortunately, tracking down the exact wrong information in the .json is a pain and a fucking half.

eringiglio commented 7 years ago

Hey, @ajfclark , how did you fix it? I have found that deleting my entire .json works, but then I have to go through and manually delete all the newly duplicated todoist tasks when I resync it and that suuuuuucks. Is there a better way?

ajfclark commented 7 years ago

I haven't found one sorry @eringiglio

I delete the stuff in habitica first and then the json and resync. That way I can just clear everything in habitica rather than trying to figure out which duplicates to delete. Still very tedious.

ajfclark commented 7 years ago

Once again, this has cropped up. Every sync attempt dies with:

/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:189
  if(apiVersion === 'v2' && res.body) {
                               ^

TypeError: Cannot read property 'body' of undefined
    at formatResponse (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:189:32)
    at /usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/lib/apiv3.js:61:7
    at Request.callback (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/node_modules/superagent/lib/node/index.js:660:30)
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/todoist-habitrpg/node_modules/habitrpg-api/node_modules/superagent/lib/node/index.js:628:10)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at TLSSocket.socketErrorListener (_http_client.js:269:9)
    at emitOne (events.js:77:13)
    at TLSSocket.emit (events.js:169:7)
    at emitErrorNT (net.js:1269:8)

I've deleted every task from Habitica but no joy, it still crashes. I've deleted the JSON file and it still crashes. My sync is currently completely broken and doesn't work at all.

This is incredibly frustrating. Can we please get some adequate debugging around this error so we can see which task is causing the problem? Even if it was just a debug mode that output every task to the console as it was syncing so we could try and narrow down where the issue is?

diyadas commented 7 years ago

Yes, I'm having the same issue. In the past, this popped up when I'd checked something off in Habitica that hadn't been checked off in Todoist, but I don't think I did that today.

ajfclark commented 7 years ago

Appears the sync is completely broken at the moment. Even with nothing in habitica and no JSON it doesn't work any more. I guess it wouldn't work for a new user either then.