Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled rejection SyntaxError: Unexpected token in JSON at position 0 #28

Closed
brookemahoney opened this issue Jun 28, 2020 · 9 comments
Assignees

Comments

@brookemahoney
Copy link

3.0.7 on Mac Mojave

When I try any lando command from any path, including just running lando with no arguments, I get the following error:

$ lando
Unhandled rejection SyntaxError: Unexpected token  in JSON at position 0
SyntaxError: Unexpected token  in JSON at position 0
    at JSON.parse (<anonymous>)
    at /snapshot/lando/build/cli/plugins/lando-pantheon/lib/utils.js
    at arrayMap (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:639:23)
    at Function.map (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:9556:14)
    at interceptor (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:16993:35)
    at thru (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:8797:14)
    at /snapshot/lando/build/cli/node_modules/lodash/lodash.js:4374:28
    at arrayReduce (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:683:21)
    at baseWrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:4373:14)
    at LazyWrapper.lazyValue [as value] (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:1859:16)
    at baseWrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:4371:25)
    at LodashWrapper.wrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:9052:14)
    at Object.getTerminusTokens (/snapshot/lando/build/cli/plugins/lando-pantheon/lib/utils.js)
    at getTokens (/snapshot/lando/build/cli/plugins/lando-pantheon/recipes/pantheon/init.js)
    at Object.options (/snapshot/lando/build/cli/plugins/lando-pantheon/recipes/pantheon/init.js)
    at /snapshot/lando/build/cli/plugins/lando-recipes/lib/options.js
From previous event:
    at processImmediate (internal/timers.js:439:21)

Tell us more

I have tried uninstalling and reinstalling Lando (including removing ~/.lando) and Docker multiple times.
I've tried with 3.0.7, 3.0.5, and 3.0.1.
I've searched the issue queue here and haven't found anything in all the issues ever filed.
I updated my version of Node to the latest LTS which didn't help.
I've spent all today, Sunday, trying to get it to work on a personal project. Yesterday it was working fine; I had multiple drupal 8 instances running without any issue. I have been using it all week on yet another project. The only real difference about the project I was trying to get to work today is that it's a Pantheon recipe. I was in the middle of setting up authorization with Terminus and setting up a pantheon.yml file, but started to run into errors like the one above.

Does this bug prevent you from using lando? Yes

@pirog
Copy link
Sponsor Member

pirog commented Jun 29, 2020

@jeffymahoney based on the error message im guessing this is where things are going awry for you
https://github.com/lando/lando/blob/master/plugins/lando-pantheon/lib/utils.js#L290

As of now Lando has assumed the files in~/.terminus/cache/tokens are valid JSON but apparently this is not an assumption we can make. I'd check out that directory and remove any files that are invalid JSON. Guessing that should get you going again. It is also worth pointing out that Lando does not modify any of these files so its highly likely that this reflects a bug in Terminus or was user error of some kind.

Regardless, we should also improve Lando to throw a better error message when this happens.

It would be great to know what file actually was invalid JSON and how it was invalid.

@dustinleblanc
Copy link

@jeffymahoney let us know what you find in the ~/.terminus/cache/tokens folder, might make good test case material if we figure out what went wrong with the files

@brookemahoney
Copy link
Author

brookemahoney commented Jun 29, 2020

I have only one file in the ~/.terminus/cache/tokens folder. It contains valid JSON. The name of the file is a private email address with no characters other than lowercase ascii and the @ symbol. The contents of the file are valid JSON. The file has exactly one line and no linebreaks. The line is:

{"token":"MYTOKEN","email":"example@example.com","date":1587944819}

I have changed the email address for privacy reasons.

Removing this folder did indeed get lando working again. Thanks so much, both of you, for your quick help with this. I haven't looked into how Lando is built and I don't know how to debug, troubleshoot, and contribute back yet. One of these days I'll take the time to learn how Lando works and be able to contribute back with pull requests, but I'm just not there yet :(

Please reach out to me if you'd like more information. I'd be happy to do a Zoom meeting or similar if you can't reproduce and you'd like to find out what it is about my system that caused this.

@pirog
Copy link
Sponsor Member

pirog commented Jun 29, 2020

I have changed your token for similar privacy reasons!

good to know, not sure why lando would say thats an invalid JSON file if it isnt, especially if removing that directory fixed it. we dont modify that directory, only read from it so i think the "bug fix" we'd want to do here is just throwing a more helpful error if lando cannot read any of the files in that directory correctly

@brookemahoney
Copy link
Author

I removed that token from Pantheon before I posted it here, so no big deal :) I wanted to give you something as close to the real thing as possible. Some error handling in that code block would certainly be nice :)

@pirog
Copy link
Sponsor Member

pirog commented Jun 29, 2020

Agreed.

It would be great to understand why exactly there was invalid JSON in there but regardless a better error message is easy enough to do.

@pirog
Copy link
Sponsor Member

pirog commented Jul 14, 2020

This will be fixed in 3.0.8

@pirog pirog closed this as completed Jul 14, 2020
@FredM
Copy link

FredM commented Mar 28, 2021

Hi,

I'm getting the same error in 3.0.26 or 3.0.28 (using the command lando version in that case):

Error: The file /home/xxxx/.terminus/cache/tokens/xxxxxxxx@gmail.com is not valid JSON
    at /snapshot/lando/build/cli/integrations/lando-pantheon/lib/utils.js
    at arrayMap (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:639:23)
    at Function.map (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:9580:14)
    at interceptor (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:17046:35)
    at thru (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:8817:14)
    at /snapshot/lando/build/cli/node_modules/lodash/lodash.js:4388:28
    at arrayReduce (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:683:21)
    at baseWrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:4387:14)
    at LazyWrapper.lazyValue [as value] (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:1859:16)
    at baseWrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:4385:25)
    at LodashWrapper.wrapperValue (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:9072:14)
    at Object.getTerminusTokens (/snapshot/lando/build/cli/integrations/lando-pantheon/lib/utils.js)
    at getTokens (/snapshot/lando/build/cli/integrations/lando-pantheon/recipes/pantheon/init.js)
    at Object.options (/snapshot/lando/build/cli/integrations/lando-pantheon/recipes/pantheon/init.js)
    at /snapshot/lando/build/cli/plugins/lando-recipes/lib/options.js
    at arrayEach (/snapshot/lando/build/cli/node_modules/lodash/lodash.js:516:11)
From previous event:
    at processImmediate (internal/timers.js:439:21)

Deleting the file "fixes" the error.

@rtfm-47 rtfm-47 transferred this issue from lando/lando Nov 24, 2021
@djassie
Copy link

djassie commented Mar 10, 2023

I got the similar error - which make me come here

The lando file was big, but there was small error - which was causing the problem.

name: Drupalmerc
recipe: drupal9
config:
  build:
    run_scripts: true
  composer_version: '2.4.3'
  via: apache
  drush: true
  php: '8.1'

Now, after lot of head crunching, the name should be all small

so, I have change only the name key

Changed :

name: drupalmerc
...

@dustinleblanc dustinleblanc removed their assignment Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants