mickgiles / homebridge-vesync

Homebridge plugin for vesync WiFi Power Outlets
6 stars 4 forks source link

SyntaxError #8

Closed dcxr7 closed 3 years ago

dcxr7 commented 3 years ago

In homebridge, getting the following:

SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse ()

it keeps reloading each time.

Full log:

at Transform.<anonymous> (C:\Users\username\AppData\Roaming\npm\node_modules\homebridge-vesync-v2\node_modules\hyper-request\hrequest.js:304:43)
at Transform.emit (events.js:327:22)
at finish (internal/streams/writable.js:657:10)
at finishMaybe (internal/streams/writable.js:644:9)
at afterWrite (internal/streams/writable.js:473:3)
at afterWriteTick (internal/streams/writable.js:453:10)
at processTicksAndRejections (internal/process/task_queues.js:79:21)

SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse () at parserFunction (C:\Users\username\AppData\Roaming\npm\node_modules\homebridge-vesync-v2\lib\client.js:13:29) at Transform. (C:\Users\username\AppData\Roaming\npm\node_modules\homebridge-vesync-v2\node_modules\hyper-request\hrequest.js:304:43) at Transform.emit (events.js:327:22) at finish (internal/streams/writable.js:657:10) at finishMaybe (internal/streams/writable.js:644:9) at afterWrite (internal/streams/writable.js:473:3) at afterWriteTick (internal/streams/writable.js:453:10) at processTicksAndRejections (internal/process/task_queues.js:79:21) [4/7/2021, 12:48:07 PM] [HB Supervisor] Homebridge Process Ended. Code: 1, Signal: null [4/7/2021, 12:48:12 PM] [HB Supervisor] Restarting Homebridge...

mickgiles commented 3 years ago

Given that the error is that the json parser is detecting an angle bracket "<" as the first character rather than valid json I suspect that you are getting a response from a proxy or firewall that is blocking the request. I've added some debugging to try to get a little more info. Can you manually install this version and send me the added logging? npm install -g mickgiles/homebridge-vesync#master

dcxr7 commented 3 years ago

appreciate your help...

so I got an error when installing that. Here is the log:

0 info it worked if it ends with ok 1 verbose cli [ 1 verbose cli 'C:\Program Files\nodejs\node.exe', 1 verbose cli 'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js', 1 verbose cli 'install', 1 verbose cli '-g', 1 verbose cli 'mickgiles/homebridge-vesync#master' 1 verbose cli ] 2 info using npm@6.14.11 3 info using node@v14.16.0 4 verbose npm-session 076b0d77f6e656a4 5 silly install loadCurrentTree 6 silly install readGlobalPackageData 7 silly fetchPackageMetaData error for github:mickgiles/homebridge-vesync#master Error while executing: 7 silly fetchPackageMetaData undefined ls-remote -h -t ssh://git@github.com/mickgiles/homebridge-vesync.git 7 silly fetchPackageMetaData 7 silly fetchPackageMetaData 7 silly fetchPackageMetaData spawn git ENOENT 8 timing stage:rollbackFailedOptional Completed in 0ms 9 timing stage:runTopLevelLifecycles Completed in 68ms 10 verbose stack Error: spawn git ENOENT 10 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19) 10 verbose stack at onErrorNT (internal/child_process.js:465:16) 10 verbose stack at processTicksAndRejections (internal/process/task_queues.js:80:21) 11 verbose cwd C:\Windows\System32 12 verbose Windows_NT 10.0.19042 13 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "-g" "mickgiles/homebridge-vesync#master" 14 verbose node v14.16.0 15 verbose npm v6.14.11 16 error code ENOENT 17 error syscall spawn git 18 error path git 19 error errno -4058 20 error enoent Error while executing: 20 error enoent undefined ls-remote -h -t ssh://git@github.com/mickgiles/homebridge-vesync.git 20 error enoent 20 error enoent 20 error enoent spawn git ENOENT 21 error enoent This is related to npm not being able to find a file. 22 verbose exit [ -4058, true ]

mickgiles commented 3 years ago

hmm, ok. I just published a new version so you can try installing it normally

dcxr7 commented 3 years ago

thanks, I tried that.. this time I got something different:

[4/7/2021, 1:52:45 PM] [VesyncPlug]

400 Bad Request

400 Bad Request

(node:32292) UnhandledPromiseRejectionWarning: null (node:32292) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)

mickgiles commented 3 years ago

ah, that's pretty much what I expected. The place that error is happening is just trying to connect to the vesync API. What do you get when you go to this url in a browser on the same machine as your homebridge? https://smartapi.vesync.com

dcxr7 commented 3 years ago

loading that URL:

{"error":{"code":4001004,"msg":"TOKEN expired"}}

mickgiles commented 3 years ago

Odd, that is the correct response. Is homebridge connecting through a proxy or a firewall?

dcxr7 commented 3 years ago

no proxy, only the windows standard firewall and I've already allowed homebridge access

dcxr7 commented 3 years ago

so, I tried disabling the firewall to see if that would resolve the issue but it did not work. The same thing appears as my prev. message since the last update

mickgiles commented 3 years ago

If you are comfortable, can you make a backup copy and then edit this file on your local device C:\Users\username\AppData\Roaming\npm\node_modules\homebridge-vesync-v2\lib\client.js after line 9 where it says baseUrl: 'https://smartapi.vesync.com', can you add the following 2 lines?

            debug: true,
            customLogger : function(verb, endpoint, time){log(verb);},

afterwards it should look like this

Screen Shot 2021-04-07 at 4 35 52 PM

Then when you restart it should have more verbose logging about the connection

mickgiles commented 3 years ago

I just uploaded a new build. Can you test when you get a chance and see if this fixes anything?

dcxr7 commented 3 years ago

Hey, sorry had to step out for a little. So I came back, updated and checked to see if it worked. I got the following error:

[4/7/2021, 6:43:34 PM] [VesyncPlug]

400 Bad Request

400 Bad Request

(node:23732) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'tk' of null at C:\Users\username\AppData\Roaming\npm\node_modules\homebridge-vesync-v2\lib\client.js:47:35 at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:93:5) (node:23732) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 211)

mickgiles commented 3 years ago

I've been playing around with this and I get that exact same error if my I use bad login credentials for my vesync account. Can you verify that your vesync login is correct in the settings?

dcxr7 commented 3 years ago

so I tried to use a bad combo user/pass and it yeilds the same error. I have logged out of the app and confirmed the login details. I even went as far as to reset my user/pass and set up something different to ensure that wasn't part of the issue. Either way it is giving the same message.

dcxr7 commented 3 years ago

anything else that could be tried?

mickgiles commented 3 years ago

ok, I've been able to reproduce. this is a windows only bug and looks to be related to the https library I'm using for connecting to vesync. I'll play around with this and figure out a solution

dcxr7 commented 3 years ago

really appreciate your help, thank you

mickgiles commented 3 years ago

can you try the new version?

dcxr7 commented 3 years ago

!!! its fixed. 🥇 good job! many thanks 👍