What Does This Rails4 error mean? fatal: exception reentered … `rescue in rollback_active_record_state!'

ⅰ亾dé卋堺 提交于 2019-12-08 14:47:17

问题


I'm getting a couple of errors in my Rails 4 appointment scheduling application that I can't seem to correct or figure out the root cause.

My seeds file keeps breaking with well known "error, stack level too deep". But when I run the method I believe it is breaking on, I get this different error:

Seeding time slots for workday no. 1
   (0.5ms)  SAVEPOINT active_record_1
   (0.5ms)  ROLLBACK TO SAVEPOINT active_record_1
fatal: exception reentered
from /Users/rskelley/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.5/lib/active_record/transactions.rb:286:in `rescue in rollback_active_record_state!'

The involved files are as follows.

Seeds.rb

puts "Seeding Workdays."

day_numbers = (1..5).to_a
5.times do
  start_time = WorkDay.time_slot_format(9)
  end_time = WorkDay.time_slot_format([5,6][rand(2)])
  rand_date = Date.today + day_numbers.slice!(0)
  WorkDay.create(start_time: start_time, end_time: end_time, date: rand_date )
end

puts "Generating Time Slots for each WorkDay"

workdays = WorkDay.all
workday_number = 1

workdays.each do |workday|
  calendar_manager = CalendarManager.new(workday: workday, date: workday.date)
  puts "Seeding time slots for workday no. #{workday_number}"
  workday_number += 1
  calendar_manager.generate_time_slots!
end

calendar_manager.rb

include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
extend AppointmentTools

attr_accessor :workday, :date, :slot_length

 def generate_time_slots!(increment=15)
    # Space between start and end
    @slot_length ||= increment

    day = self.workday.date
    hour = 9
    minute = 0
    @time_slots = Array.new

    33.times do
      beginning = TimeOfDay.parse(hour) + minute.minutes
      ending = beginning + @slot_length.minutes
      time_slot = TimeSlot.create work_day_id: self.workday.id, start_time: beginning.strftime("%I:%M %p"), end_time: ending.strftime("%I:%M %p"), date: day
      @time_slots << time_slot
      minute += @slot_length
    end
  end

Going through my commit history, I am not aware of any changes made to the generate_time_slots! method, and it worked previously. I'm using Rails 4, Ruby 2.


回答1:


So I just had a similar issue with a similar error message.

It is just that ActiveRecord is being "helpful" and telling you that you called the same method recursively. Basically rather than saying you ran out of stack it is looking at the trace it originally got and determining it is in fact a reentered recursive call.

At least, that solved my issue.



来源:https://stackoverflow.com/questions/26121671/what-does-this-rails4-error-mean-fatal-exception-reentered-rescue-in-roll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!