diff options
author | Kasumi Hanazuki <[email protected]> | 2023-11-28 23:05:26 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-11-28 14:05:31 +0000 |
commit | 5fc71feb6ca8b62d51f9b6421cb26c9f1228be17 (patch) | |
tree | 557b2e130bc76d182a8bd93391f9686167c60122 /vsnprintf.c | |
parent | 9365b78d49bfee1a1b40d02c7f6ac8b3a9954b8d (diff) |
[ruby/irb] Rescue errors from main.to_s/inspect when formatting
prompt
(https://github.com/ruby/irb/pull/791)
Currently, IRB just terminates if `main.to_s` raises while IRB
constructs the prompt string. This can easily happen if the user wants
to start an IRB session in the instance scope of an uninitialized
object, for example:
```
class C
def initialize
binding.irb
@values = []
end
def to_s = @values.join(',') # raises if uninitialized
end
C.new
```
This patch makes IRB rescue from such an exception and displays the
class name of the exception instead of `main.to_s` to indicate some
error has occurred.
We may display more detailed information about the exception, but this
patch chooses not to do so because 1) the prompt has limited space,
2) users can evaluate `to_s` in IRB to examine the error if they want,
and 3) obtaining the details can also raise, which requires nested
exception handling and can be complicated.
https://github.com/ruby/irb/commit/412ab26067
Diffstat (limited to 'vsnprintf.c')
0 files changed, 0 insertions, 0 deletions