Skip to content

Commit 1f8a3ae

Browse files
aycabtawin93
andcommitted
Finalize when exception occurred
Co-authored-by: Alex Gittemeier <me@a.lexg.dev>
1 parent 7e6f33e commit 1f8a3ae

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/reline.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ def readline(prompt = '', add_hist = false)
290290

291291
may_req_ambiguous_char_width
292292
line_editor.reset(prompt, encoding: Reline::IOGate.encoding)
293-
line_editor.set_signal_handlers
294293
if multiline
295294
line_editor.multiline_on
296295
if block_given?
@@ -320,6 +319,7 @@ def readline(prompt = '', add_hist = false)
320319
line_editor.rerender
321320

322321
begin
322+
line_editor.set_signal_handlers
323323
prev_pasting_state = false
324324
loop do
325325
prev_pasting_state = Reline::IOGate.in_pasting?
@@ -348,6 +348,11 @@ def readline(prompt = '', add_hist = false)
348348
line_editor.finalize
349349
Reline::IOGate.deprep(otio)
350350
raise e
351+
rescue Exception
352+
# Including Interrupt
353+
line_editor.finalize
354+
Reline::IOGate.deprep(otio)
355+
raise
351356
end
352357

353358
line_editor.finalize

lib/reline/line_editor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def set_signal_handlers
235235
when 'EXIT'
236236
exit
237237
else
238-
@old_trap.call
238+
@old_trap.call if @old_trap.respond_to?(:call)
239239
end
240240
}
241241
begin

0 commit comments

Comments
 (0)