Skip to content

Script exits on JSON parsing error #6

@cstephen

Description

@cstephen

The following error caused my script to exit after running for ~3 weeks:

Error: Error parsing twitter reply: `89793","indices":[13,36],"media_url":"http:\/\/pbs.twimg.com\/ext_tw_video_thumb\/895412798070689793\/pu\/img\/M4Y57VvnZ40Z52rj.jpg","media_url_https":"https:\/\/pbs.twimg.com\/ext_tw_video_thumb\/895412798070689793\/pu\/img\/M4Y57VvnZ40Z52rj.jpg","url":"https:\/\/t.co\/sPQAK28OrF","display_url":"pic.twitter.com\/sPQAK28OrF","expanded_url":"https:\/\/twitter.com\/DiazKai\/status\/895412845818503170\/video\/1","type":"video","sizes":{"small":{"w":340,"h":604,"resize":"fit"},"large":{"w":720,"h":1280,"resize":"fit"},"thumb":{"w":150,"h":150,"resize":"crop"},"medium":{"w":600,"h":1067,"resize":"fit"}},"video_info":{"aspect_ratio":[9,16],"duration_millis":6167,"variants":[{"bitrate":320000,"content_type":"video\/mp4","url":"https:\/\/video.twimg.com\/ext_tw_video\/895412798070689793\/pu\/vid\/180x320\/tYenM019Ngjn0n61.mp4"},{"bitrate":832000,"content_type":"video\/mp4","url":"https:\/\/video.twimg.com\/ext_tw_video\/895412798070689793\/pu\/vid\/360x640\/j0W-x7R89z8JW0ti.mp4"},{"bitrate":2176000,"content_type":"video\/mp4","url":"https:\/\/video.twimg.com\/ext_tw_video\/895412798070689793\/pu\/vid\/720x1280\/1cdqK9nqtd9pXiNV.mp4"},{"content_type":"application\/x-mpegURL","url":"https:\/\/video.twimg.com\/ext_tw_video\/895412798070689793\/pu\/pl\/NZfk3ZWWZ_pHusHU.m3u8"}]}}]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en"},"is_quote_status":true,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"","expanded_url":null,"indices":[134,134]}],"user_mentions":[{"screen_name":"SouljaHoward","name":"\u3164\u3164\u3164*","id":323369295,"id_str":"323369295","indices":[3,16]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1502948583929"}`, error message `SyntaxError: Unexpected string in JSON at position 5`
    at Parser.parse (~/hashtag-count/node_modules/twit/lib/parser.js:44:28)
    at Gunzip.<anonymous> (~/hashtag-count/node_modules/twit/lib/streaming-api-connection.js:139:21)
    at emitOne (events.js:96:13)
    at Gunzip.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Gunzip.Readable.push (_stream_readable.js:134:10)
    at Gunzip.Transform.push (_stream_transform.js:128:32)
    at Zlib.callback (zlib.js:598:14)

hashtag-count needs to be modified to handle/ignore errors like this so they don't kill the process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions