SpeedETab / bypass

0 stars 1 forks source link

Implement prevision for hash object #1

Closed Joseworks closed 8 years ago

Joseworks commented 8 years ago

Implements #1

allolex commented 8 years ago

You need to bump the version to 0.1.19 @Joseworks

Joseworks commented 8 years ago

@allolex please review, thank you.

allolex commented 8 years ago
def valid_json?(json)
  begin
    JSON.parse json
    return true
  rescue JSON::ParserError => e
    return false
  end
end

It's probably better to try to parse it as JSON, then fail over if it's not. That will eliminate other holes in the armor.

Joseworks commented 8 years ago

@allolex
That blows up, because just attempting to do:

      begin
        JSON.parse json
        return true
      rescue JSON::ParserError => e
        return false
      end

results on a different error:

rake aborted!
NoMethodError: undefined method `[]' for nil:NilClass

on:

      @categories = CategoryCollection.new parsed_menu["categories"]
allolex commented 8 years ago

@Joseworks parsed_menu should not be empty under any circumstances by the time it reaches that point. If there is no menu to parse, then there's a problem and the import should not happen at all.

With the code above:

parsed_menu = if valid_json?(opts[:menu])
  JSON.parse opts[:menu]
else
  opts[:menu]
end

raise ":menu cannot be empty" if opts[:menu].empty?
Joseworks commented 8 years ago

@allolex , the problem is not the parsed_menu being empty, the problem is that trying to run

 if valid_json?(opts[:menu]) 

results on:

  ArgumentError: strict_parse() expected a String or IO Object 

which halts execution on the spot