danthareja / node-google-apps-script

[DEPRECATED - use clasp instead] The easiest way to develop Google Apps Script projects
MIT License
353 stars 70 forks source link

gapps init causes syntax error if response body is not JSON #40

Open jacktaylor418 opened 8 years ago

jacktaylor418 commented 8 years ago

I got a syntax error from the command gapps init 123...xyz (with "123...xyz" substituted by my real project ID). Here's the error:

[jack@mycomputer myproject]$ gapps init 123...xyz
Error parsing project files
Script file ID not found. Please input an ID and try again.
Error running init command
Unhandled rejection SyntaxError: Unexpected token <
    at Object.parse (native)
    at /usr/lib/node_modules/node-google-apps-script/lib/manifestor.js:79:19
    at tryCatcher (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:505:31)
    at Promise._settlePromiseAt (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:581:18)
    at Promise._settlePromises (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/promise.js:697:14)
    at Async._drainQueue (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/lib/node_modules/node-google-apps-script/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

After some digging, I found that JSON.parse in line 79 of manifestor.js was expecting JSON but actually received an HTML page. The HTML page was one saying "You need permission ... Want in? Ask the owner for access, or switch to an account with permission." I think I may have made a mistake when getting my credentials in the Google Developer Console, hence the authentication error.

It would be nice to handle this more elegantly, as the error message is pretty confusing - it makes it seem like the error is something to do with the project ID itself, when it is actually an authentication problem.

georgeh commented 7 years ago

I had this issue - I had created my project with the wrong Google account. I fixed it by sharing the project with the correct account.