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

Panic if CWD gets deleted #2527

Closed
zen3ger opened this issue May 21, 2022 · 4 comments
Closed

Panic if CWD gets deleted #2527

zen3ger opened this issue May 21, 2022 · 4 comments
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@zen3ger
Copy link
Contributor

zen3ger commented May 21, 2022

Summary

If a document is being edited when the current working directory of helix has been deleted then helix will panic.

There's quite a lot of places where std::env:current_dir() just has an .expect() on it so I'm opening the issue instead of going ahead and patch things up so we can agree on how this should be handled in general.

Reproduction Steps

I tried this:

  1. mkdir temp
  2. touch myfile.txt
  3. cd temp; hx myfile.txt
  4. In a different terminal rm -rf temp
  5. In gnome-terminal it was enough to click the terminal, but with Alacritty it needed to bring up e.g. the prompt

I expected this to happen:
Pop up that directory no longer exists or something sensible, but not a panic.

Instead, this happened:

thread 'main' panicked at 'couldn't determine current directory: Os { code: 2, kind: NotFound, message: "No such file or directory" }', helix-core/src/path.rs:87:45
stack backtrace:
   0: rust_begin_unwind
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
   2: core::result::unwrap_failed
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5
   3: core::result::Result<T,E>::expect
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23
   4: helix_core::path::get_relative_path
             at /home/zen3ger/Projects/helix/helix-core/src/path.rs:87:21
   5: core::ops::function::FnOnce::call_once
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:227:5
   6: core::option::Option<T>::map
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/option.rs:912:29
   7: helix_view::document::Document::relative_path
             at /home/zen3ger/Projects/helix/helix-view/src/document.rs:929:9
   8: helix_term::ui::editor::EditorView::render_statusline
             at /home/zen3ger/Projects/helix/helix-term/src/ui/editor.rs:777:28
   9: helix_term::ui::editor::EditorView::render_view
             at /home/zen3ger/Projects/helix/helix-term/src/ui/editor.rs:161:9
  10: <helix_term::ui::editor::EditorView as helix_term::compositor::Component>::render
             at /home/zen3ger/Projects/helix/helix-term/src/ui/editor.rs:1319:13
  11: helix_term::compositor::Compositor::render
             at /home/zen3ger/Projects/helix/helix-term/src/compositor.rs:183:13
  12: helix_term::application::Application::render
             at /home/zen3ger/Projects/helix/helix-term/src/application.rs:215:9
  13: helix_term::application::Application::handle_terminal_events
             at /home/zen3ger/Projects/helix/helix-term/src/application.rs:388:13
  14: helix_term::application::Application::event_loop::{{closure}}
             at /home/zen3ger/Projects/helix/helix-term/src/application.rs:236:21
  15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  16: helix_term::application::Application::run::{{closure}}
             at /home/zen3ger/Projects/helix/helix-term/src/application.rs:753:26
  17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  18: hx::main_impl::{{closure}}
             at /home/zen3ger/Projects/helix/helix-term/src/main.rs:116:30
  19: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/future/mod.rs:91:19
  20: tokio::park::thread::CachedParkThread::block_on::{{closure}}
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/park/thread.rs:263:54
  21: tokio::coop::with_budget::{{closure}}
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/coop.rs:102:9
  22: std::thread::local::LocalKey<T>::try_with
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/thread/local.rs:442:16
  23: std::thread::local::LocalKey<T>::with
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/thread/local.rs:418:9
  24: tokio::coop::with_budget
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/coop.rs:95:5
  25: tokio::coop::budget
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/coop.rs:72:5
  26: tokio::park::thread::CachedParkThread::block_on
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/park/thread.rs:263:31
  27: tokio::runtime::enter::Enter::block_on
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/runtime/enter.rs:151:13
  28: tokio::runtime::thread_pool::ThreadPool::block_on
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/runtime/thread_pool/mod.rs:81:9
  29: tokio::runtime::Runtime::block_on
             at /home/zen3ger/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/tokio-1.18.2/src/runtime/mod.rs:477:43
  30: hx::main_impl
             at /home/zen3ger/Projects/helix/helix-term/src/main.rs:118:5
  31: hx::main
             at /home/zen3ger/Projects/helix/helix-term/src/main.rs:35:21
  32: core::ops::function::FnOnce::call_once
             at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Helix log

No response

Platform

Linux, FreeBSD, MacOS

Terminal Emulator

gnome-terminal, alacritty, iterm2

Helix Version

22.03-234-g8df8ff27

@zen3ger zen3ger added the C-bug Category: This is a bug label May 21, 2022
@kirawi kirawi added the A-helix-term Area: Helix term improvements label May 23, 2022
@archseer
Copy link
Member

Agreed, this should call editor.set_error instead 👍🏻

@zen3ger
Copy link
Contributor Author

zen3ger commented May 23, 2022

That's going to be a bit tricky, not everything has access to the helix_view::editor::Editor to report the error in the UI.

Maybe it would be good to have a helix-log crate which has similar macros to log? E.g. just a struct that wraps a tokio::sync::mspc::unbounded_channel() pair that way the receiving end could be simply hooked into the Application::event_loop and dispatch it to the component that handles error reporting (currently the Editor). The sending end then could be safely cloned in every helix_log::error!() invocation.

@aral
Copy link
Contributor

aral commented Jul 5, 2023

Also, it’s possible that the directory will only be gone for a given amount of time but then return.

Use case: You have helix open at the node_modules folder in a project and you’re hacking some node modules in place to debug something. Then wipe the node_modules folder and do an npm install.

(In fact, I’m not sure this is the right issue for this use case as it ties in more with helix not updating when source files update – something that has bitten me quite a few times, including while doing some live coding on stage at a conference…)

@pascalkuthe pascalkuthe removed the E-good-first-issue Call for participation: Issues suitable for new contributors label Jul 5, 2023
@pascalkuthe
Copy link
Member

fixed by #7185 but seems we forgot to close this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

No branches or pull requests

5 participants