cabal icon indicating copy to clipboard operation
cabal copied to clipboard

cabal init -n fails with opaque error message when git not installed

Open jnhnum1 opened this issue 2 years ago • 2 comments

On a new machine with Cabal 3.8.1.0, I tried running cabal init -n newapp and got what appeared to be an uncaught exception: git: readCreateProcessWithExitCode: posix_spawnp: does not exist (No such file or directory) It took a little while to figure out, but the issue seems to be that I didn't have git installed. Perhaps this case could be handled with a more helpful error message.

jnhnum1 avatar Sep 17 '22 07:09 jnhnum1

Relevant code: https://github.com/haskell/cabal/blob/55b4ed9f6626613cfd965887bd16f3ffdca1aba6/cabal-install/src/Distribution/Client/Init/NonInteractive/Heuristics.hs#L178-L186

Should be easy to fix. Anyone?

ulysses4ever avatar Sep 17 '22 12:09 ulysses4ever

@ptkato care to make a patch?

gbaz avatar Sep 29 '22 02:09 gbaz

Should an error be thrown if git is not installed in this case? Then perhaps something like this would work: Then you could check something like if fst' info /= ExitSuccess then ... on the second readProcessWithExitCode call with the --global flag?

BasLaa avatar Feb 11 '23 12:02 BasLaa

git is needed to retrieve the user name and user email information for the cabal file. Now, it's the most reliable way of getting such info for the non-interactive workflow. I'm torn if we should throw an error or not, I don't recall if such user info is mandatory, even if it is, I think an error would be out of proportion (what if the user doesn't want git installed?); we could instead throw a warning to make the user aware that the name and email could not be retrieved instead.

ptkato avatar Feb 11 '23 13:02 ptkato

We definitely don't want to fail (in any way) if git is not installed. A warning, perhaps, could be added, but I'm not big on that either: I think a warning is justified when something could go wrong, and it's not the case here.

ulysses4ever avatar Feb 11 '23 13:02 ulysses4ever

Perhaps simply an empty default value for user name and user email when git is not installed with a note instead of a warning?

BasLaa avatar Feb 11 '23 13:02 BasLaa

Yes, sorry, by warning I didn't really mean "warning", but what @BasLaa suggested instead.

ptkato avatar Feb 11 '23 13:02 ptkato

No, you’re good. I’m just thinking aloud.

Empty default is fine. For the “note” idea: I’d be curious to see a sketch, but I’m open minded.

ulysses4ever avatar Feb 11 '23 14:02 ulysses4ever

I can give it a try this weekend.

BasLaa avatar Feb 11 '23 14:02 BasLaa

This has been merged, so this should be fine to close now.

BasLaa avatar Mar 05 '23 18:03 BasLaa