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

Paket crashes when HOME is not set #3791

Open
matthid opened this issue Feb 9, 2020 · 3 comments
Open

Paket crashes when HOME is not set #3791

matthid opened this issue Feb 9, 2020 · 3 comments

Comments

@matthid
Copy link
Member

matthid commented Feb 9, 2020

Description

This seems to happen in Azure DevOps Pipelines when running as root:

isaacabraham/vsts-fsharp#33

Repro steps

  • Unset HOME on linux
  • Run the netcore version of paket (I think the full framework one might not have this problem)

Expected behavior

Paket works

Actual behavior

Paket crashes

Known workarounds

Set HOME

@forki
Copy link
Member

forki commented Feb 9, 2020

O_o ideas?

@matthid
Copy link
Member Author

matthid commented Feb 9, 2020

The problem is

let ProgramFiles = Environment.GetFolderPath Environment.SpecialFolder.ProgramFiles

Which will crash here:

let GetFolderPath sf =
let envVar, monoPathSuffix =
match sf with
| ApplicationData -> "APPDATA", ".config"
| UserProfile -> "USERPROFILE", ""
| LocalApplicationData -> "LocalAppData", ".local/share"
| ProgramFiles -> "PROGRAMFILES", ".programfiles"
| ProgramFilesX86 -> "PROGRAMFILES(X86)", ".programfilesX86"
let isWindows =
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
System.Runtime.InteropServices.OSPlatform.Windows)
let homePath =
if isWindows then
let defaultPath = Environment.GetEnvironmentVariable("USERPROFILE")
if System.String.IsNullOrEmpty defaultPath then
Environment.GetEnvironmentVariable("HOME")
else defaultPath
else Environment.GetEnvironmentVariable("HOME")
if isWindows then
let res = Environment.GetEnvironmentVariable(envVar)
if System.String.IsNullOrEmpty res then
System.IO.Path.Combine(homePath, monoPathSuffix)
else res
else
System.IO.Path.Combine(homePath, monoPathSuffix)

If we cannot come up with something better we could at least check homePath for null and throw a better exception (something along the lines of please set HOME environment variable). To be honest, I don't have any other idea on how to find a good path (ie the real fix).

@matthid
Copy link
Member Author

matthid commented Feb 9, 2020

Generally, exceptions in static initialization are always very unexpected (and generally badly reported) but that is something for another day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants