cabal
cabal copied to clipboard
cabal init -n fails with opaque error message when git not installed
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.
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?
@ptkato care to make a patch?
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?
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.
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.
Perhaps simply an empty default value for user name and user email when git is not installed with a note instead of a warning?
Yes, sorry, by warning I didn't really mean "warning", but what @BasLaa suggested instead.
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.
I can give it a try this weekend.
This has been merged, so this should be fine to close now.