Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `[]' for nil:NilClass #112

Open
streetlogics opened this issue Jan 21, 2017 · 1 comment
Open

NoMethodError: undefined method `[]' for nil:NilClass #112

streetlogics opened this issue Jan 21, 2017 · 1 comment
Assignees
Labels
Milestone

Comments

@streetlogics
Copy link

streetlogics commented Jan 21, 2017

This commit from @numbata introduced a new syntax for getting the remote login data: 8808d0f

I have two projects that use this gem, updated both on the same day, same server environment (ruby 2.3.0), same server, etc...

One of the projects works fine.

The second project throws an error saying:

NoMethodError: undefined method `[]' for nil:NilClass
capistrano-db-tasks/lib/capistrano-db-tasks/database.rb:115:in `block (2 levels) in initialize'

If a put a breakpoint on that line and inspect the content of dirty_config_content, I see:

"Usage:\r\n  rails new APP_PATH [options]\r\n\r\nOptions:\r\n  -r, [--ruby=PATH]                                      # Path to the Ruby binary of your choice\r\n                                                         # Default: ~/.rbenv/versions/2.3.0/bin/ruby\r\n  -m, [--template=TEMPLATE]                              # Path to some application template (can be a filesystem path or URL)\r\n      [--skip-gemfile], [--no-skip-gemfile]              # Don't create a Gemfile\r\n  -B, [--skip-bundle], [--no-skip-bundle]                # Don't run bundle install\r\n  -G, [--skip-git], [--no-skip-git]                      # Skip .gitignore file\r\n      [--skip-keeps], [--no-skip-keeps]                  # Skip source control .keep files\r\n  -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files\r\n  -S, [--skip-sprockets], [--no-skip-sprockets]          # Skip Sprockets files\r\n      [--skip-spring], [--no-skip-spring]                # Don't install Spring application preloader\r\n  -d, [--database=DATABASE]                              # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)\r\n                                                         # Default: sqlite3\r\n  -j, [--javascript=JAVASCRIPT]                          # Preconfigure for selected JavaScript library\r\n                                                         # Default: jquery\r\n  -J, [--skip-javascript], [--no-skip-javascript]        # Skip JavaScript files\r\n      [--dev], [--no-dev]                                # Setup the application with Gemfile pointing to your Rails checkout\r\n      [--edge], [--no-edge]                              # Setup the application with Gemfile pointing to Rails repository\r\n      [--skip-turbolinks], [--no-skip-turbolinks]        # Skip turbolinks gem\r\n  -T, [--skip-test-unit], [--no-skip-test-unit]          # Skip Test::Unit files\r\n      [--rc=RC]                                          # Path to file containing extra configuration options for rails command\r\n      [--no-rc], [--no-no-rc]                            # Skip loading of extra configuration options from .railsrc file\r\n\r\nRuntime options:\r\n  -f, [--force]                    # Overwrite files that already exist\r\n  -p, [--pretend], [--no-pretend]  # Run but do not make any changes\r\n  -q, [--quiet], [--no-quiet]      # Suppress status output\r\n  -s, [--skip], [--no-skip]        # Skip files that already exist\r\n\r\nRails options:\r\n  -h, [--help], [--no-help]        # Show this help message and quit\r\n  -v, [--version], [--no-version]  # Show Rails version number and quit\r\n\r\nDescription:\r\n    The 'rails new' command creates a new Rails application with a default\r\n    directory structure and configuration at the path you specify.\r\n\r\n    You can specify extra command-line arguments to be used every time\r\n    'rails new' runs in the .railsrc configuration file in your home directory.\r\n\r\n    Note that the arguments specified in the .railsrc file don't affect the\r\n    defaults values shown above in this help message.\r\n\r\nExample:\r\n    rails new ~/Code/Ruby/weblog\r\n\r\n    This generates a skeletal Rails installation in ~/Code/Ruby/weblog.\r\n    See the README in the newly created application to get going."

If I put the same breakpoint in and output the contents of that variable in my other project, i can see there's a line with the following syntax at the beginning:

__CAPISTRANODB_CONFIG_BEGIN_FLAG__---\r\n:adapter: mysql2\r\n:encoding: utf8\r\n:username: MYSQLUSERNAME\r\n:password: PASSWORD\r\n:database: DATABASE_NAME\r\n:host: DATABASE_HOST\r\n:flags: 2\r\n__CAPISTRANODB_CONFIG_END_FLAG__\r\n

If I take the old syntax from the commit above and put that in my console where I've got the breakpoint, I get:

"development:\r\n  adapter: mysql2\r\n  encoding: utf8\r\n  database: DATABASE\r\n  username: USERNAME\r\n  password: PASSWORD\r\n\r\n# Warning: The database defined as \"test\" will be erased and\r\n# re-generated from your development database when you run \"rake\".\r\n# Do not set this db to the same as development or production.\r\ntest:\r\n  adapter: mysql2\r\n  encoding: utf8\r\n  database: DATABASE\r\n  username: USERNAME\r\n  password: PASSWORD\r\n\r\nstaging:\r\n  adapter: mysql2\r\n  encoding: utf8\r\n  database: DATABASE\r\n  username: USERNAME\r\n  password: PASSWORD\r\n\r\nproduction:\r\n  adapter: mysql2\r\n  encoding: utf8\r\n database: DATABASE\r\n  username: USERNAME\r\n  password: PASSWORD\r\n  host: DATABASE_HOST"

And the next line from the old code appears to properly set the @config var:

 @config = YAML.load(ERB.new(@config).result)[@cap.fetch(:rails_env).to_s]
{"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"DATABASE", "username"=>"USERNAME", "password"=>"PASSWORD", "host"=>DATABASE_HOST"}

I can't really explain why, but I can definitely say that this new syntax is causing a really weird error using the latest version.

@numbata numbata self-assigned this Feb 27, 2018
@numbata numbata added the bug label Feb 27, 2018
@numbata numbata added this to the v0.7 milestone Feb 27, 2018
@numbata
Copy link
Collaborator

numbata commented Feb 27, 2018

@streetlogics what version of rails do your project use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants