semifor / Net-Twitter

A Perl interface to the Twitter APIs
83 stars 37 forks source link

Consider using JSON::MaybeXS #59

Closed oalders closed 8 years ago

oalders commented 8 years ago

Would you be open to using JSON::MaybeXS rather than JSON? It appears to be much less buggy and also uses Cpanel::JSON::XS under the hood where possible.

I'm happy to send a pull request.

I came across this because I came across a puzzling error in Net::Twitter::Core::_parse_result() where the JSON parsing was throwing an error. This error goes away with Cpanel::JSON::XS. Since there's no catch block to warn or die it took me a while to track down.

malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before \"\\x{1f}\\x{fffd}\\x{8}\\x{0}...\") at /vagrant/inc/wundercharts-plugin/local/lib/perl5/x86_64-linux-gnu-thread-multi/Moose/Meta/Method/Delegation.pm line 110.\n\tNet::Twitter::Core::from_json(Net::Twitter_v4_01010_with__API_RESTv1_1__OAuth=HASH(0x45738f0), '\\x{1f}\\x{8b}\\x{8}\\x{0}\\x{0}\\x{0}\\x{0}\\x{0}\\x{0}\\x{0}\\x{ec}Wmo\\x{db}6\
\x{10}\\x{fe}+\\x{84}\\x{b6}\\x{e}\\x{1b}\\x{a6}\\x{d8}\\x{d4}\\x{9b}%\\x{b9}(\\x{b6} I;\\x{c}X[\\x{ac})\\x{fa}!\\x{a}\\x{4}Z\\x{a2}l\\x{b6}\\x{12}\\x{a9}
\\x{92}T]/\\x{c8}\\x{7f}\\x{df}Qo\\x{96}\\x{9d}d...')
[truncated stack trace]
oalders commented 8 years ago

The bug seems to be somehow related to me supplying my own ua arg when creating the object, so I think I have it solved on my end. I'm still happy to send a PR for the JSON handling, though.

semifor commented 8 years ago

Happy to accept a PR for the JSON handling provided it solves your problem without introducing new issues. Twitter's JSON is quite generic. Wish I understood exactly what happened there.