Show resolver being used when stack ghci is invoked outside of a project directory#4521
Conversation
| when (null localTargets && isNothing mfileTargets) $ | ||
|
|
||
| when (null localTargets && isNothing mfileTargets) $ do | ||
| let project = fst $ fromJust mproject |
There was a problem hiding this comment.
Even if there is no currently known way for this to be Nothing, there could possibly be a way now or in the future, and the error thrown by fromJust is pretty frustratingly vague.
How about instead, for the Nothing case, using something like error "Invariant violated: no project". One nice thing about using error is that it will show where in stack's code the error occurred.
There was a problem hiding this comment.
I agree, ignoring the Nothing case is pretty ugly. I was thinking about this some more and decided to try something else: simply not print the resolver version if the project is Nothing. Would this work? I can do the error instead, but it's basically the same thing I had before, except it has a more useful error message.
|
The code related to resolvers and snapshots has changed quite a bit since I last looked, so I can't give direct guidance. However, it seems like |
|
@mgsloan thanks for your review! I was digging through the |
|
@wafelj Welcome! Yeah I also dug around Looks to me like |
stack ghci is invoked outside of a project directorystack ghci is invoked outside of a project directory
|
@mgsloan @wafelj there was a large refactoring in #4412 and now Stack doesn' use |
|
@mgsloan @qrilka thanks. I looked into that and changed the code - now it passes the name from Also, two questions:
|
|
Sounds like a good idea to me. |
|
@qrilka changed to read name directly from BuildConfig and changed the field to smwSnapshotName. Also changed output to snapshot instead of resolver. Looks good? |
Fix for #3651.
Approach: read
ProjectfromConfig, getSnapshotLocationand compiler info from it and use that to get resolver using theloadResolverfunction. To my understanding it is theoretically possible that there is no project information in config (it's wrapped inMaybe). But I'm assuming this never actually happens because if I try to delete the~/.stack/global-project/stack.yaml, a new one is recreated whenstack ghciis run again. This is why I assumed it's safe to usefromJust. If there is a better approach, I'd love to hear about it.Disclaimer: I'm new to Haskell and to stack, and this is my first open-source contribution. Any feedback is most appreciated!