From aeae10b8903ec781ba1a99f7894dd488b1595f83 Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Wed, 18 Oct 2023 00:52:00 +0100 Subject: [PATCH] Clear STAN suggestion --- doc/maintainers/stack_errors.md | 1 + src/Stack/Build/ConstructPlan.hs | 10 ++++++++-- src/Stack/Types/Build/Exception.hs | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/maintainers/stack_errors.md b/doc/maintainers/stack_errors.md index c18d654aa8..6f15ce94b4 100644 --- a/doc/maintainers/stack_errors.md +++ b/doc/maintainers/stack_errors.md @@ -360,6 +360,7 @@ to take stock of the errors that Stack itself can raise, by reference to the [S-3121] | TemplateHaskellNotFoundBug [S-6901] | HaddockIndexNotFound [S-5452] | ShowBuildErrorBug + [S-2696] | CallStackEmptyBug ~~~ - `Stack.Types.Build.BuildPrettyException` diff --git a/src/Stack/Build/ConstructPlan.hs b/src/Stack/Build/ConstructPlan.hs index a80b2926b6..ccc171468d 100644 --- a/src/Stack/Build/ConstructPlan.hs +++ b/src/Stack/Build/ConstructPlan.hs @@ -21,6 +21,7 @@ import Distribution.Types.BuildType ( BuildType (Configure) ) import Distribution.Types.PackageName ( mkPackageName ) import Generics.Deriving.Monoid ( memptydefault, mappenddefault ) import Path ( parent ) +import qualified RIO.NonEmpty as NE import RIO.Process ( HasProcessContext (..), findExecutable ) import RIO.State ( State, execState ) import Stack.Build.Cache ( tryGetFlagCache ) @@ -79,6 +80,7 @@ import Stack.Types.SourceMap import Stack.Types.Version ( latestApplicableVersion, versionRangeText, withinRange ) import System.Environment ( lookupEnv ) +import Data.List.NonEmpty (nonEmpty) data PackageInfo = PIOnlyInstalled InstallLocation Installed @@ -619,13 +621,17 @@ addDep name packageInfo = do Nothing -> do -- This could happen for GHC boot libraries missing from -- Hackage. - cs <- asks (L.tail . callStack) + cs <- asks (nonEmpty . callStack) + cs' <- maybe + (throwIO CallStackEmptyBug) + (pure . NE.tail) + cs prettyWarnL $ flow "No latest package revision found for" : style Current (fromString $ packageNameString name) <> "," : flow "dependency callstack:" : mkNarrativeList Nothing False - (map (fromString . packageNameString) cs :: [StyleDoc]) + (map (fromString . packageNameString) cs' :: [StyleDoc]) pure Nothing Just (_rev, cfKey, treeKey) -> pure $ Just $ diff --git a/src/Stack/Types/Build/Exception.hs b/src/Stack/Types/Build/Exception.hs index d7e8443e81..c9b8d26bf6 100644 --- a/src/Stack/Types/Build/Exception.hs +++ b/src/Stack/Types/Build/Exception.hs @@ -81,6 +81,7 @@ data BuildException | TemplateHaskellNotFoundBug | HaddockIndexNotFound | ShowBuildErrorBug + | CallStackEmptyBug deriving (Show, Typeable) instance Exception BuildException where @@ -251,6 +252,8 @@ instance Exception BuildException where ++ "No local or snapshot doc index found to open." displayException ShowBuildErrorBug = bugReport "[S-5452]" "Unexpected case in showBuildError." + displayException CallStackEmptyBug = bugReport "[S-2696]" $ + "addDep: call stack is empty." data BuildPrettyException = ConstructPlanFailed