RJNY RJNY - 1 year ago 47
Ruby Question

Unknown Argument Error "-p" when deploying to heroku

We are deploying a rails app to Heroku. The app should be making a youtube api call, using the Trollop Gem as a command line parser. We keep getting this error back.

2014-07-30T23:17:57.526014+00:00 app[web.1]: Error: unknown argument '-p'.
2014-07-30T23:17:57.526020+00:00 app[web.1]: Try --help for help.
2014-07-30T23:17:57.526541+00:00 app[web.1]: Completed 500 Internal Server Error in 7466ms

This is what our Trollop code looks like.

def self.youtube_search(query)
youtube_service_api_name = "youtube"
youtube_api_version = "v3"
# opts = HTTParty.get("https://www.youtube.com/results?search_query=russia")
opts = Trollop::options do
opt :q, 'Search term', :source => String, :default => query
opt :maxResults, 'Max results', :source => :int, :default => 25

What's much stranger is that it was working an hour ago and now it's not. Does anyone have any ideas? This doesn't seem to be documented anywhere.

Answer Source

Trollop will fail when provided with undefined arguments. In your code the -q option is defined but -p is not.

Here are the relevant lines in the parse method:


339       unless sym
340         next 0 if ignore_invalid_options
341         raise CommandlineError, "unknown argument '#{arg}'" unless sym
342       end

As for why it was working previously, perhaps you were passing -q then and inadvertently passing -p now?