Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IRB doesn't save input history when exited with exit! #612

Closed
st0012 opened this issue Jun 25, 2023 · 3 comments · Fixed by #851
Closed

IRB doesn't save input history when exited with exit! #612

st0012 opened this issue Jun 25, 2023 · 3 comments · Fixed by #851
Labels
bug Something isn't working

Comments

@st0012
Copy link
Member

st0012 commented Jun 25, 2023

Because IRB relies on IRB.conf[:AT_EXIT] config, which will be run in at_exit, to save a session's input history. When users exit the session with exit!, the input is not written.

Reproduction Steps

  1. Open an IRB session and run

    irb(main):001:0> a = 1
    => 1
    irb(main):002:0> b = 2
    => 2
    irb(main):003:0> exit
    
  2. Open another session and type up-arrow to check the above history

  3. In the same session, run

    irb(main):001:0> c = 3
    => 3
    irb(main):002:0> d = 4
    => 4
    irb(main):003:0> exit! # with a ! this time
    
  4. Open another session and type up-arrow to view history

Expected Behaviour

Input from step 3 should be part of the history

Actual Behaviour

Input from step 3 is lost

@st0012 st0012 added the bug Something isn't working label Jun 25, 2023
@tompng
Copy link
Member

tompng commented Jul 3, 2023

This is the expected behavior of Kernel.exit!. Skips all at_exit handlers and ensure statements.
I think we can add exit! command that executes Kernel.exit

@st0012
Copy link
Member Author

st0012 commented Jul 3, 2023

I'm thinking about the other direction: we patch Kernel.exit! to save history instead.
In some cases, users may want to skip at_exit hooks when they exit the session, like when debugging at_exit issues that hang the program. If we make exit! the same as exit, then there's no obvious way to leave the session without the hang (ofc, they can call Kernel.exit! manually but it's not intuitive).

@tompng
Copy link
Member

tompng commented Jul 4, 2023

Just for my case, most of the time I use exit! is when I want to just Kernel.exit because exit is overridden in irb.
like

loop{
  ...
  binding.irb # want to exit the program after debugging/investigating. don't want to skip cleanup (ensure, at_exit)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants