Giter Site home page Giter Site logo

Comments (9)

phoet avatar phoet commented on August 27, 2024

i can confirm this issue.

here is a snippet how to reproduce it:

Loading development environment (Rails 3.0.7)
ruby-1.9.2-p180 :004 > require 'crack'
ruby-1.9.2-p180 :002 > url = 'http://picasaweb.google.com/data/feed/base/user/phoet6/?alt=json'
ruby-1.9.2-p180 :001 > HTTPClient.get(url).content
ruby-1.9.2-p180 :003 > resp = HTTPClient.get(url).content
ruby-1.9.2-p180 :005 > resp = Crack::JSON.parse(resp)
Psych::SyntaxError: couldn't parse YAML at line 1 column 395
    from /Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:148:in `parse'
    from /Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:148:in `parse_stream'
    from /Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:119:in `parse'
    from /Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/psych.rb:106:in `load'
    from /Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement/gems/crack-0.1.8/lib/crack/json.rb:12:in `parse'
    from (irb):5
    from /Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement/gems/railties-3.0.7/lib/rails/commands/console.rb:44:in `start'
    from /Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement/gems/railties-3.0.7/lib/rails/commands/console.rb:8:in `start'
    from /Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement/gems/railties-3.0.7/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:10:in `require'
    from script/rails:10:in `<main>'

from crack.

phoet avatar phoet commented on August 27, 2024

it took me some time to reproduce the issue on a second machine. at first i thought it might be a problem with the latest iMac, but i can reproduce it on my macbook too.

here is what i did:

$ rvm get head
$ rvm install 1.9.2
ruby-1.9.2-p180@basement:

  system:
    uname:       "Darwin ernst.local 10.7.1 Darwin Kernel Version 10.7.1: Thu Jan 27 18:47:00 PST 2011; root:xnu-1504.10.48~2/RELEASE_X86_64 x86_64"
    bash:        "/bin/bash => GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)"
    zsh:         "/bin/zsh => zsh 4.3.9 (i386-apple-darwin10.0)"

  rvm:
    version:      "rvm 1.6.18 by Wayne E. Seguin ([email protected]) [https://rvm.beginrescueend.com/]"

  ruby:
    interpreter:  "ruby"
    version:      "1.9.2p180"
    date:         "2011-02-18"
    platform:     "x86_64-darwin10.7.1"
    patchlevel:   "2011-02-18 revision 30909"
    full_version: "ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.1]"

  homes:
    gem:          "/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement"
    ruby:         "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180"

  binaries:
    ruby:         "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/bin/ruby"
    irb:          "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/bin/irb"
    gem:          "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/bin/gem"
    rake:         "/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@global/bin/rake"

  environment:
    PATH:         "/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement/bin:/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@global/bin:/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/bin:/Users/peterschroder/.rvm/bin:/Users/peterschroder/Library/android:/Users/peterschroder/.script:/Users/peterschroder/Library/grails/bin:/Users/peterschroder/Library/groovy/bin:/Users/peterschroder/.gem/ruby/1.8/bin:/Users/peterschroder/Library/maven/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/opt/nginx/sbin"
    GEM_HOME:     "/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement"
    GEM_PATH:     "/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@basement:/Users/peterschroder/.rvm/gems/ruby-1.9.2-p180@global"
    MY_RUBY_HOME: "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180"
    IRBRC:        "/Users/peterschroder/.rvm/rubies/ruby-1.9.2-p180/.irbrc"
    RUBYOPT:      "rubygems"
    gemset:       "basement"

$ bundle --version
Bundler version 1.0.14

$ rails -v
Rails 3.0.7

Since RVM is using some YAML library during installation of 1.9.2 it might be related to that:

--no-same-owner
Configuring yaml in /Users/peterschroder/.rvm/src/yaml-0.1.3.
Compiling yaml in /Users/peterschroder/.rvm/src/yaml-0.1.3.
Installing yaml to /Users/peterschroder/.rvm/usr

from crack.

phoet avatar phoet commented on August 27, 2024

i tried a rather radical approach and removed my rvm installation and replacing it with an old/random version, but it worked out:

paule@phoet:~○$ rm -rf .rvm
paule@phoet:~○$ curl -s https://rvm.beginrescueend.com/install/rvm -o rvm-installer ; chmod +x rvm-installer ; ./rvm-installer --version 1.6.2

from crack.

zmoazeni avatar zmoazeni commented on August 27, 2024

I don't know the fix for rvm or crack, but this worked for me:

require 'httparty'
requre 'json'
response = HTTParty.get("http://someurl.com", :format => :plain)
JSON.parse(response.body)

It effectively ignores Crack's implementation. Not ideal, but good 'nuff for my use case.

from crack.

denkristoffer avatar denkristoffer commented on August 27, 2024

Adding

YAML::ENGINE.yamler = "syck"

to the top of my file fixed this for me.

from crack.

matt-glover avatar matt-glover commented on August 27, 2024

It is effectively tied to the syck versus psych issue. They don't have identical JSON parsing behavior and do not throw exactly the same errors up the stack. If, for example, you pass in HTML and ask it to parse it as if it were JSON Crack via syck will catch the error from syck and wrap it in a Crack::ParseError whereas Crack via psych will let the Psych::SyntaxError pass through.

The Psych::Syntax error type inherits from SyntaxError instead of StandardError so something like a vanilla rescue statement wouldn't catch the PsychError while it may catch a similar error condition from syck simply because it is wrapped differently.

For more information on the PsychError see the following issue: ruby/psych#23

from crack.

m3talsmith avatar m3talsmith commented on August 27, 2024

+1 to @sachse. I dropped that in config/initializers/httparty.rb and I'm good.

from crack.

thbar avatar thbar commented on August 27, 2024

@sachse thank you! You're making my day.

from crack.

jnunemaker avatar jnunemaker commented on August 27, 2024

Closing since someone suggested solution.

from crack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.