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

Starship fails when %USERPROFILE% is changed #3526

Closed
CLIDragon opened this issue Jan 27, 2022 · 2 comments · Fixed by #3773
Closed

Starship fails when %USERPROFILE% is changed #3526

CLIDragon opened this issue Jan 27, 2022 · 2 comments · Fixed by #3773
Labels
🐛 bug Something isn't working as expected.

Comments

@CLIDragon
Copy link
Contributor

CLIDragon commented Jan 27, 2022

Current Behavior

Start your preferred shell however you want (using starship), then set %USERPROFILE% to any path that is not a valid home directory. Curiously, when %USERPROFILE% is set to null, or to a valid home directory that is not yours, starship works fine. However, the following error is raised when %USERPROFILE% is not a valid home directory.

thread 'main' panicked at 'Unable to find home directory', C:\Users\CLIDragon\.cargo\registry\src\github.com-1ecc6299db9ec823\starship-1.2.1\src\logger.rs:27:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected Behavior

To continue to work as normal.

Additional context/Screenshots

This error is really strange. In src/log.rs:27, crate::utils::home_dir() is called, which calls into directories_next, which ultimately calls into dirs_sys_next. The strange part is that dirs_next also calls dir_sys_next, yet provides the correct response when %USERPROFILE% is modified. I've cross-posted this issue over on xdg-rs/dirs#57, to hopefully get some input on why this occurs.

fn main() {
    // Returns None.
    let home_dir = directories_next::BaseDirs::new().map(|base_dirs| base_dirs.home_dir().to_owned());
    println!("Home directory (next): {:#?}", home_dir);   

    // Correctly returns Some("C:\Users\CLIDragon")
    let home_dir = dirs_next::home_dir();
    println!("Home dir (next): {:#?}", home_dir);
}

Possible Solution

Switch to using dirs_next instead of directories_next.

Environment

  • Starship version: 1.2.1
  • powershell version: 7.2.1
  • Operating system: Windows 10.0.19043
  • Terminal emulator: Windows Terminal 1.11.3471.0
  • Git Commit Hash:
  • Branch/Tag:
  • Rust Version: rustc 1.58.1 (db9d1b20b 2022-01-20)
  • Rust channel: stable-x86_64-pc-windows-msvc release
  • Build Time: 2022-01-27 17:04:43 +10:00

Relevant Shell Configuration

Invoke-Expression (&starship init powershell)

Starship Configuration

@davidkna
Copy link
Member

I assume the requirements and the amount of directories gathered are higher for BaseDirs::new() because it supports a larger number of directories instead of just home_path().

@CLIDragon
Copy link
Contributor Author

I assume the requirements and the amount of directories gathered are higher for BaseDirs::new() because it supports a larger number of directories instead of just home_path().

BaseDirs::new() requires the equivalent of dirs_next::data_dir() and dirs_next::data_local_dir(). Interestingly, despite both calling into SHGetKnownFolderPath under the hood, both data_dir() and data_local_dir() fail when %USERPROFILE% is changed. I suppose the question is: Why does data_dir() and data_local_dir() fail when %USERPROFILE% is changed?

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

Successfully merging a pull request may close this issue.

2 participants