SyntaxError: Unexpected token ';', ";{
Looks like something is wrong here:
SyntaxError: Unexpected token ';', ";{
"ip":"... is not valid JSON
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (C:\Users\Administrator\Desktop\data-analysis-co\node_modules\node-ipinfo\dist\src\ipinfoWrapper.js:109:67)
at IncomingMessage.emit (node:events:519:28)
at emitCloseNT (node:internal/streams/destroy:147:10)
at process.processTicksAndRejections (node:internal/process/task_queues:81:21)
this error came from this line, maybe malformed response.
that's a very simple case:
Example:
function foo() {
console.log('Hi');
setTimeout(() => {
console.log('lets throwing an exception.. :}}')
throw new Error('An Amazing Error!');
}, 2000)
}
try {
foo()
} catch (error) {
console.log('Error Catched!: ' + error);
}
Output:
Hi
lets throwing an exception.. :}}
/Users/mojtaba/personalp/test.js:5
throw new Error('An Amazing Error!');
^
Error: An Amazing Error!
at Timeout._onTimeout (/Users/mojtaba/personalp/test.js:5:15)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7)
Node.js v20.15.1
We can see that Error Catched! is not here..
Hi @mojidev7 Which version of node-ipinfo are you using?
If it's < 3.1.1 then the issue is that they don't have a fix for this issue which was added in July 2022.
Let me know if the error persists after the update.
I this still happening (very rarely) in 3.5.3
We will look into this as soon as possible.
CC: @max-ipinfo
@pz129 We are investigating the issues, and are currently unsure how to replicate the scenario. Can you please reach out to us through our support desk ([email protected])? We would appreciate more information from you. Thanks!
Best Regards, Abdullah (DevRel @ IPinfo.io)
After a year, this issue still hasn't been fixed. My server just crashed in production again—the second time this year. Adding a simple try/catch around JSON.parse(xxx) would resolve it. Check my solution here: https://github.com/ipinfo/node/issues/88
@sayhicoelho sorry for the wait. I've had to focus on other things unfortunately.
I'll do my best to take a look today. Thank you for your understanding.
@sayhicoelho sorry for the wait. I've had to focus on other things unfortunately.
I'll do my best to take a look today. Thank you for your understanding.
Hi @max-ipinfo , any update about it ? Or at least how to catch it on our side to prevent crash on production for now? Thank you 🙏
@vguillot @sayhicoelho as a quick update, I've been investigating this bogus JSON response and we do not have a clear reproduction case on our end.
That said, I'm definitely open to adding try/catch blocks to prevent transitive failures on your end.
@max-ipinfo It isn't possible to try/catch on our end because the error occurs in an event listener.
See my example here.
@max-ipinfo It isn't possible to
try/catchon our end because the error occurs in a event listener.See my example here.
@sayhicoelho sorry if I wasn't clear in my response. I meant adding try/catch around the JSON.parse calls throughout our library, calling the reject callback in case of an error.
@mojidev7 I just pushed a fix to https://www.npmjs.com/package/node-ipinfo/v/3.5.5
Thank you for your patience!
@sayhicoelho we've just released v4 of the library, replacing use of http(s) with node-fetch. The use of node-fetch means we're no longer directly using event listeners that can escape error catching, so wrapping lookupIp in try/catch will catch errors. We also think that the use of http(s) was the cause of the underlying error (a ; being prepend to the response when reading from the stream) so the error itself should stop.
Please update to v4 at your convenience and let us know if you encounter any further issues.
@max-ipinfo @abdullahdevrel @shrink Good job thanks If faced again will inform you