avram icon indicating copy to clipboard operation
avram copied to clipboard

Empty enumerable (Enumerable::EmptyError)

Open jwoertink opened this issue 3 years ago • 1 comments

I'm not sure if this is an actual bug, or just a bad error, but this error happens if you pass in params to an operation and there's no permitted keys.

class SaveUser < User::SaveOperation
  permit_columns :name
end
# user:beepbeep=true
SaveUser.create(params) do |_,_|
end

Will need to track down where this is happening.

jwoertink avatar Jun 19 '22 16:06 jwoertink

This is caused from this line

https://github.com/luckyframework/avram/blob/21345fd17faaa2a7b5d59777b86bbff67a860269/src/avram/save_operation.cr#L283

When we call insert, we use a RETURNING statement which should return a record, but I think if the insert fails, then nothing is returned, and we basically call [].first which raises this error. One option could be to rescue this error and re-raise a Avram::RecordInsertError or something...

Chances are, update has the same issue:

https://github.com/luckyframework/avram/blob/21345fd17faaa2a7b5d59777b86bbff67a860269/src/avram/save_operation.cr#L290

jwoertink avatar Sep 21 '22 16:09 jwoertink