elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.48k stars 658 forks source link

Permission Denied Error Due to Unset `ELM_HOME` Environment Variable in `Stuff` Module #2315

Open blackeuler opened 8 months ago

blackeuler commented 8 months ago

Description

When running the Elm compiler without the ELM_HOME environment variable set, it defaults to using the the location of elm im assuming for storing data. In certain environments, the process may lack the necessary permissions to write to this directory, resulting in a Permission Denied error.

This issue stems from the getElmHome function within the Stuff module in the Elm compiler source code. Below is the relevant snippet from the Stuff module:

getElmHome :: IO FilePath
getElmHome =
  do  maybeCustomHome <- Env.lookupEnv "ELM_HOME"
      case maybeCustomHome of
        Just customHome -> return customHome
        Nothing -> Dir.getAppUserDataDirectory "elm"

In the absence of the ELM_HOME environment variable, getElmHome defaults to using AppUserDataDirectory.

Steps to Reproduce

  1. Ensure the ELM_HOME environment variable is not set.
  2. Run the Elm compiler command in an environment where the AppUserDataDirectory is not writable by the process.
  3. Observe the Permission Denied error.
github-actions[bot] commented 8 months ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

lydell commented 8 months ago

Is this a request for a better error message in this case?

What is an example of an environment where the process lacks permission?

bburdette commented 8 months ago

defaults to using the the location of elm

Maybe this is more a problem of the environment. The name getAppUserDataDirectory implies a location that is writable by the current user. If it is giving the location of the elm executable then that's a problem - I wouldn't expect the executable location to be writable in most distros.

blackeuler commented 8 months ago

Sorry that was my Interpretation of the getAppUserDataDirectory. Im not sure where exactly it was trying to write to. This came up when trying to automate some things with elm make. We were calling elm make from another program process. It all worked locally but then we ran into the createDirectory permissionDenied error when deploying it on fly.io. I think there should be a nicer error message handled by elm. #2042 references a similar issue