ruby Errors

22 error patterns

ruby3 fixes

Logstash Grok pattern match failure

logstash.*Error.*Grok.*pattern.*match failure

  • Test pattern with Grok Debugger tool
  • Add tag_on_failure and handle non-matching events
ruby3 fixes

Logstash pipeline terminated unexpectedly

logstash.*PipelineTerminatedError.*pipeline.*shutdown

  • Check Logstash logs for underlying error causing shutdown
  • Increase JVM heap for Logstash: -Xms1g -Xmx1g in jvm.options
ruby3 fixes

Method called on nil object

NoMethodError.*undefined method.*for (nil:NilClass|nil)

  • Use safe navigation operator: object&.method
  • Add nil check: if object.present? or unless object.nil?
ruby3 fixes

Undefined method on object

NoMethodError.*undefined method.*for.*:.*

  • Check the object's class with .class — it may not be what you expect
  • Verify the method exists: object.respond_to?(:method_name)
ruby3 fixes

ActiveRecord record not found

ActiveRecord::RecordNotFound.*Couldn't find.*with

  • Use find_by instead of find — it returns nil instead of raising
  • Add rescue ActiveRecord::RecordNotFound for graceful handling
ruby3 fixes

ActiveRecord validation failure on save!

ActiveRecord::RecordInvalid.*Validation failed

  • Use save instead of save! to get false instead of exception
  • Check model.errors.full_messages for specific validation failures
ruby4 fixes

Rails routing error - no matching route

No route matches.*\{.*\}

  • Run rails routes to see all available routes
  • Add the missing route to config/routes.rb
ruby3 fixes

Pending database migrations

Migrations are pending.*run.*db:migrate

  • Run rails db:migrate to apply pending migrations
  • Run rails db:migrate:status to check migration status
ruby3 fixes

Pending migration prevents app start

ActiveRecord::PendingMigrationError

  • Run rails db:migrate
  • If migration is broken, fix the migration file or run rails db:rollback
ruby4 fixes

Gem version conflict in Bundler

Bundler could not find compatible versions for gem

  • Run bundle update <gem_name> to resolve the specific gem
  • Check Gemfile for overly strict version pins
ruby3 fixes

Required file or gem not found

LoadError.*cannot load such file

  • Install the missing gem: gem install <name> or add to Gemfile
  • Check require statement spelling and path
ruby3 fixes

Uninitialized constant reference

NameError.*uninitialized constant

  • Check class/module naming matches file path (Rails autoloading)
  • Add require or require_relative for the file defining the constant
ruby3 fixes

Wrong number of arguments passed to method

ArgumentError.*wrong number of arguments.*given.*expected

  • Check the method signature for required vs optional parameters
  • Use keyword arguments for clarity: def method(name:, age: nil)
ruby3 fixes

Database column does not exist

ActiveRecord::StatementInvalid.*PG::.*column.*does not exist

  • Create a migration to add the column: rails g migration AddColumnToTable
  • Run pending migrations: rails db:migrate
ruby3 fixes

Required parameter missing from request

ActionController::ParameterMissing.*param is missing or.*empty

  • Ensure the form/request sends the required param nested correctly
  • Check strong params: params.require(:model).permit(:field)
ruby3 fixes

Gem version mismatch at runtime

Gem::LoadError.*Specified.*but.*was loaded

  • Run bundle exec before the command to use Bundler's resolved versions
  • Update the conflicting gem: bundle update <gem>
ruby4 fixes

Unique constraint violation in database

ActiveRecord::RecordNotUnique.*duplicate key value violates unique constraint

  • Add uniqueness validation to model: validates :field, uniqueness: true
  • Use find_or_create_by instead of create
ruby3 fixes

Implicit type conversion error

TypeError.*no implicit conversion of.*into String

  • Explicitly convert: .to_s, .to_i, .to_f as needed
  • Use string interpolation which calls to_s automatically: "value: #{var}"
ruby3 fixes

Ruby syntax error

SyntaxError.*unexpected.*expecting

  • Check for missing end keyword matching if/def/do/class
  • Look for unclosed string literals or parentheses
ruby3 fixes

Database does not exist

ActiveRecord::NoDatabaseError

  • Run rails db:create to create the database
  • Check database.yml for correct database name and credentials
ruby3 fixes

Port already in use

Errno::EADDRINUSE.*Address already in use.*bind

  • Kill the process using the port: lsof -i :3000 then kill PID
  • Use a different port: rails s -p 3001
ruby3 fixes

Undefined variable in view template

ActionView::Template::Error.*undefined local variable or method

  • Pass the variable from controller: @variable in action
  • Use local_assigns.key?(:var) for partials with optional locals