OK.
So, if I want to:
- Get result of transaction if everything is OK
- Get result of `after_rollback` block if there is `Sequel::Rollback`
- And get raised any other exception
I should use local variables like:
def foo
result = nil
DB.transaction do
DB.after_rollback { result = validation_errors }
raise Sequel::Rollback unless entity.valid?
result = entity.save
end
result
end
Right? There is no more compact way?
On Tuesday, August 7, 2018 at 9:41:34 PM UTC+3, Jeremy Evans wrote:
>
> On Tuesday, August 7, 2018 at 11:22:19 AM UTC-7, Alexander Popov wrote:
>>
>> I'm OK with exception raising, but… there is code:
>>
>> sequel -E sqlite:/ -c 'def foo; DB.transaction{DB.after_rollback {
>> return :ar }; raise}; end; foo'
>> I, [2018-08-07T21:21:16.084229 #7520] INFO -- : (0.000075s) PRAGMA
>> foreign_keys = 1
>> I, [2018-08-07T21:21:16.084301 #7520] INFO -- : (0.000013s) PRAGMA
>> case_sensitive_like = 1
>> I, [2018-08-07T21:21:16.084577 #7520] INFO -- : (0.000062s) SELECT
>> sqlite_version()
>> I, [2018-08-07T21:21:16.084668 #7520] INFO -- : (0.000028s) BEGIN
>> I, [2018-08-07T21:21:16.084785 #7520] INFO -- : (0.000045s) ROLLBACK
>>
>>
>> And there is no exception.
>>
>
> You are using return inside after_rollback. This is the equivalent of:
>
> def transaction
> raise
> ensure
> return :ar if $!
> end
>
> It is expected that an exception will not be raised in such cases. Sequel
> is not suppressing the exception, your code is.
>
> Don't use a non-local exit inside after_rollback (either return inside a
> proc or similar control flow such as throw) if you want the exception to be
> raised.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.