JuliaLang / juliaup

Julia installer and version multiplexer
MIT License
993 stars 85 forks source link

Julia Installer Crash Report (Better Unix Base directories specifications ) #308

Open ghyatzo opened 2 years ago

ghyatzo commented 2 years ago

Hello, I am on an M1 Mac. I encountered this error report:

name = 'Juliainstaller'
operating_system = 'unix:OSX'
crate_version = '1.6.4'
explanation = '''
Panic occurred in file 'src/operations.rs' at line 534
'''
cause = '''
called `Result::unwrap()` on an `Err` value: Failed to open juliaup config file.

Caused by:
    No such file or directory (os error 2)'''
method = 'Panic'
backtrace = '''

   0: 0x102dd664c - juliaup::command_config_modifypath::run_command_config_modifypath::h22055a10e45fa8e4
   1: 0x102d1d794 - juliainstaller::main::hec60d2626a25bbd4
   2: 0x102d0c340 - std::sys_common::backtrace::__rust_begin_short_backtrace::h38b7456c5d856e39
   3: 0x102d2085c - _main'''

The installer configuration which I selected was the following:

✔ Do you want to install with these custom configuration choices? · Customize installation
✔ Enter the folder where you want to install Juliaup · /Users/user/.juliaup
✔ Do you want to add the Julia binaries to your PATH by manipulating various shell startup scripts? · no
✔ Do you want to add channel specific symlinks? · no
✔ Enter minutes between check for new version at julia startup, use 0 to disable · 1440
✔ Enter minutes between check for new version by a background task, use 0 to disable · 0

Most notably, I requested not to automatically modify the .zshrc file to add julia to the PATH (I rather do it by hand). The culprit seems to be

pub fn remove_binfolder_from_path_in_shell_scripts() -> Result<()> {
    let paths = find_shell_scripts_to_be_modified()?;

    paths.into_iter().for_each(|p| {
        remove_path_from_specific_file(p).unwrap();
    });

    Ok(())
}

I don't know rust enough, but since I requested no config file modifications, the variable paths should be empty, but we still try to iterate through it, without checks. Maybe rusts handles this on his own and the issue is further up?

Actually, I notice also that the function find_shell_scripts_to_be_modified() assumes that the .zshrc file is in the home folder. But i keep my .zshrc file in the ~/.config/zsh folder. This assumption most likely caused the crash.

If that is the case a possible fix could be: Instead of defaulting to the home directory, use the $ZDOTDIR env variable (which I use to set the dot dir for zsh to the previously mentioned non-default location). Quoting the zsh man pages shipped with the OS:

Commands are then read from $ZDOTDIR/.zshenv.  If the shell is a login shell,
 commands are read from /etc/zprofile and then $ZDOTDIR/.zprofile.  
Then, if the shell is interactive, commands are read from /etc/zshrc and then $ZDOTDIR/.zshrc.  
Finally, if the shell is a login shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
[...]
If ZDOTDIR is unset, HOME is used instead.

P.S.: I found rather strange that the code went trough these routines even after electing to not have any startup file modified.

ghyatzo commented 2 years ago

Symlinking my .zshrc into the home folder fixed the crash and the installation went though. Still, I believe that using ZDOTDIR is a better approach as it allows the script to better adapt to the environment it is running in.

ghyatzo commented 2 years ago

This also happens when trying to uninstall, and again it happens at the step: Removing PATH modifications in startup scripts. when from the configuration choosen during the installation it should know no modifications were made to begin with.

ghyatzo commented 2 years ago

The XDG base directories are a standard for unix systems that could be a good idea to implement to make linux and mac os installations more robust. for example, the juliaupself.json could find home in the XDG_DATA_HOME directory if set.