cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.9k stars 178 forks source link

Panic when .bash_history is missing #37

Closed calexicoz closed 5 years ago

calexicoz commented 5 years ago

Hi,

I started to get those messages whenever I open a new terminal:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:1009:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I can confirm they are coming from McFly because they disappear as soon as I remove the integration in my profile. Ie if I comment out this:

if [[ -f "$(brew --prefix)/opt/mcfly/mcfly.bash" ]]; then
  source "$(brew --prefix)/opt/mcfly/mcfly.bash"
fi

Sadly, the backtrace is not helpful:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:1009:5
stack backtrace:
   0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>

I'm not 100% sure why/when it started. I'm guessing something changed on my machine but I'm not quite sure what. I upgraded to Mojave a couple weeks back but this only started a couple days ago. Aside from the message, everything else still works fine: I can use McFly and it records my commands properly.

Ideas?

Thanks!

cantino commented 5 years ago

Hey @calexicoz! Darn, thanks for letting me know! I wish I knew where that was happening. Can you confirm that when mcfly is loaded in your shell, the value of the environment variable MCFLY_HISTORY in your shell points to a real file? MCFLY_SESSION_ID should also be set.

calexicoz commented 5 years ago

Ok, I figured it out: the issue was my bash history file was missing (~/.bash_history). It disappeared 2 days ago. I'll have to figure out why, but restoring it fixed the error.

Thanks for the help!

cantino commented 5 years ago

I'm glad you figured it out. I'll re-open this issue since I should add code to detect when this happens, for whatever reason.

cantino commented 5 years ago

Fixed in fd4a16f.

paxperscientiam commented 5 years ago

Hello @cantino , i'm running into the same panic error with latest binary. My history file is also intact.

EDIT: NVM. Turns out I was confused. I incorrectly thought I had to source mcfly.bash or use mcfly binary directly.

Turns out "both" is the answer. Working beautifully now! Thanks.

cantino commented 5 years ago

Glad it's working!