Dealing with a LocalJumpError

Public, Troubleshooting, Ruby General

harrylevine

Created: Jun 20, 2016     Updated: Jun 20, 2016


This is commonly caused by having return called within a block.

Here is an example. This example triggered an Airbrake error of type LocalJumpError:

task :decrement_taken_pto_from_salaried_employees => :environment do
  today = Date.current

  return if today.sunday? || today.monday?
  DecrementPto::SalariedEmployees.deduct_salaried_pto
end

Here is the refactored code that removes the return call within the block:

task :decrement_taken_pto_from_salaried_employees => :environment do
  today = Date.current

  unless today.sunday? || today.monday?
   DecrementPto::SalariedEmployees.deduct_salaried_pto
  end
end