compiler icon indicating copy to clipboard operation
compiler copied to clipboard

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

Open blackeuler opened this issue 2 years ago • 4 comments

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.

blackeuler avatar Oct 30 '23 03:10 blackeuler

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Oct 30 '23 03:10 github-actions[bot]

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

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

lydell avatar Oct 30 '23 06:10 lydell

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.

bburdette avatar Oct 30 '23 13:10 bburdette

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

blackeuler avatar Oct 30 '23 15:10 blackeuler