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

cabal init -n fails when cabal is not in $PATH #9687

Open
fgaz opened this issue Feb 2, 2024 · 3 comments
Open

cabal init -n fails when cabal is not in $PATH #9687

fgaz opened this issue Feb 2, 2024 · 3 comments

Comments

@fgaz
Copy link
Member

fgaz commented Feb 2, 2024

Describe the bug

cabal init -n fails when cabal is not in $PATH. seems like it wants to call itself?

cabal: readCreateProcessWithExitCode: posix_spawnp: does not exist (No such file or directory)

To Reproduce
Steps to reproduce the behavior:

Ensure cabal is not in $PATH

$ mkdir mypackage
$ cd mypackage
$ /path/to/cabal init -n

Expected behavior

The package is initialized

System information

Additional context

@cloudyluna
Copy link

cloudyluna commented May 25, 2024

Hello! A Haskell newbie here (so my findings could be totally wrong 🥲).

I've pinpointed the location of the bug to be at:

(_, verString, _) <- readProcessWithExitCode "cabal" ["--version"] ""

A workaround to make this command (when cabal is not present in the PATH) work is to supply --cabal-version flag with a default Cabal spec version, i.e:

cloudyluna@suse:/tmp> cabal-3.10.3.0 init -n --cabal-version=3.0 apple
[Log] Guessing dependencies...
[Log] Using cabal specification: 3.0
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] Creating fresh file apple.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.

One way to solve this that comes to my mind is:

  • We check for readProcessWithExitCode for successful exit code and continue on normally, else we go straight to returningdefaultCabalVersion.

Update 1
I found that readProcessWithExitCode will fail with the same error if the command it calls doesn't exist anyways. So we should check for the existence of cabal in PATH first beforehand and then we proceed with deciding whether we wanna skip directly to return defaultCabalVersion if it doesn't exist in PATH or continue on with the existing version heuristic normally otherwise. Perhaps simple findExecutable from directory package or reusing findProgramOnSearchPath could work here.

Do let me know if anyone have any better suggestions 🙂

@fgaz
Copy link
Member Author

fgaz commented May 26, 2024

  • We check for readProcessWithExitCode for successful exit code and continue on normally, else we go straight to returningdefaultCabalVersion.

Sounds good, but I'm also wondering why don't we just use defaultCabalVersion in all cases (cc @emilypi)

@emilypi
Copy link
Member

emilypi commented May 26, 2024

Yeah that sounds fine to me. Thanks for the issue!

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

No branches or pull requests

3 participants