[#114348] [Ruby master Feature#19832] Method#destructive?, UnboundMethod#destructive? — "sawa (Tsuyoshi Sawada) via ruby-core" <ruby-core@...>

Issue #19832 has been reported by sawa (Tsuyoshi Sawada).

15 messages 2023/08/06

[#114365] [Ruby master Bug#19834] Segmentation fault while running in docker — "ramachandran@... (Ramachandran A) via ruby-core" <ruby-core@...>

Issue #19834 has been reported by ramachandran@mallow-tech.com (Ramachandran A).

7 messages 2023/08/09

[#114380] [Ruby master Bug#19837] Concurrent calls to Process.waitpid2 misbehave on Ruby 3.1 & 3.2 — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>

Issue #19837 has been reported by kjtsanaktsidis (KJ Tsanaktsidis).

7 messages 2023/08/11

[#114399] [Ruby master Feature#19839] Need a method to check if two ranges overlap — "shouichi (Shouichi KAMIYA) via ruby-core" <ruby-core@...>

Issue #19839 has been reported by shouichi (Shouichi KAMIYA).

27 messages 2023/08/18

[#114410] [Ruby master Bug#19841] Marshal.dump stack overflow with recursive Time — "segiddins (Samuel Giddins) via ruby-core" <ruby-core@...>

Issue #19841 has been reported by segiddins (Samuel Giddins).

9 messages 2023/08/18

[#114422] [Ruby master Feature#19842] Intorduce M:N threads — "ko1 (Koichi Sasada) via ruby-core" <ruby-core@...>

Issue #19842 has been reported by ko1 (Koichi Sasada).

30 messages 2023/08/21

[#114590] [Ruby master Bug#19857] Eval coverage is reset after each `eval`. — "ioquatix (Samuel Williams) via ruby-core" <ruby-core@...>

Issue #19857 has been reported by ioquatix (Samuel Williams).

21 messages 2023/08/30

[ruby-core:114480] [Ruby master Misc#19740] Block taking methods can't differentiate between a non-local return and a throw

From: "matz (Yukihiro Matsumoto) via ruby-core" <ruby-core@...>
Date: 2023-08-24 09:03:31 UTC
List: ruby-core #114480
Issue #19740 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Closed

Unlike other languages e.g., C++ or Java, Ruby's `throw` is for non-local **return**, so that there's no reason to treat `return` and `throw` differently.
Use exceptions to represent failures. I understand this issue was caused by `timeout` misused `catch/trhow`. But `timeout` is fixed now.

Matz.


----------------------------------------
Misc #19740: Block taking methods can't differentiate between a non-local return and a throw
https://bugs.ruby-lang.org/issues/19740#change-104266

* Author: byroot (Jean Boussier)
* Status: Closed
* Priority: Normal
----------------------------------------
Opening this as Misc, as at this stage I don't have a fully formed feature request. 

Ref: https://github.com/ruby/ruby/commit/1a3bcf103c582b20e9ea70dfed0ee68b24243f55
Ref: https://github.com/ruby/timeout/pull/30
Ref: https://github.com/rails/rails/pull/29333

### Context

Rails has this problem in the Active Record transaction API.

The way it works is that it yields to a block, and if no error was raised the SQL transaction is committed, otherwise it's rolled back:

```ruby
User.transaction do
  do_thing
end # COMMIT
```

or

```ruby
User.transaction do
  raise SomeError
end # ROLLBACK
```

The problem is that there are more ways a method can be exited:

```ruby
User.transaction do
  return # non-local exit
end
```

```ruby
User.transaction do
  throw :something
end
```

In the case of a non-local return, we'd want to commit the transaction, but in the case of a throw, particularly since it's internally used by `Timeout.timeout` since Ruby 2.1, we'd rather consider that an error and rollback.

But as far as I'm aware, there is not way to distinguish the two cases.


```ruby
def transaction
  returned = false
  yield
  returned = true
ensure
  if $!
    # error was raised
  elsif returned
    # no uniwnd
  else
    # non-local return or throw, don't know
  end
end
```

I think it could be useful to have a way to access the currently thrown object, similar to `$!` for such cases, or some other way to tell what is going on.

There is some discussion going on in https://github.com/ruby/timeout/pull/30 about whether `Timeout` should throw or raise, and that may solve part of the problem, but regardless of where this leads, I think being able to check if something is being thrown would be valuable.

cc @matthewd
FYI @jeremyevans0 @Eregon 



-- 
https://bugs.ruby-lang.org/
 ______________________________________________
 ruby-core mailing list -- ruby-core@ml.ruby-lang.org
 To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
 ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/

In This Thread

Prev Next