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 with opaque error message when git not installed #8478

Closed
jnhnum1 opened this issue Sep 17, 2022 · 10 comments
Closed

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

jnhnum1 opened this issue Sep 17, 2022 · 10 comments

Comments

@jnhnum1
Copy link

jnhnum1 commented Sep 17, 2022

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.

@ulysses4ever
Copy link
Collaborator

Relevant code:

guessGitInfo :: Interactive m => String -> m String
guessGitInfo target = do
info <- readProcessWithExitCode "git" ["config", "--local", target] ""
if null $ snd' info
then trim . snd' <$> readProcessWithExitCode "git" ["config", "--global", target] ""
else return . trim $ snd' info
where
snd' (_, x, _) = x

Should be easy to fix. Anyone?

@gbaz
Copy link
Collaborator

gbaz commented Sep 29, 2022

@ptkato care to make a patch?

@BasLaa
Copy link
Collaborator

BasLaa commented Feb 11, 2023

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?

@ptkato
Copy link
Collaborator

ptkato commented Feb 11, 2023

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.

@ulysses4ever
Copy link
Collaborator

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.

@BasLaa
Copy link
Collaborator

BasLaa commented Feb 11, 2023

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

@ptkato
Copy link
Collaborator

ptkato commented Feb 11, 2023

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

@ulysses4ever
Copy link
Collaborator

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.

@BasLaa
Copy link
Collaborator

BasLaa commented Feb 11, 2023

I can give it a try this weekend.

@BasLaa
Copy link
Collaborator

BasLaa commented Mar 5, 2023

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

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

5 participants