diff --git a/package.yaml b/package.yaml index 55fa20b7f3..6f916e5341 100644 --- a/package.yaml +++ b/package.yaml @@ -271,6 +271,7 @@ library: - Stack.Types.Compiler - Stack.Types.Config - Stack.Types.Config.Build + - Stack.Types.Config.Exception - Stack.Types.ConfigMonoid - Stack.Types.Docker - Stack.Types.DockerEntrypoint diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 586f4dded6..a21fe3a20f 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -104,13 +104,14 @@ import Stack.Types.ColorWhen ( ColorWhen (..) ) import Stack.Types.Compiler ( defaultCompilerRepository ) import Stack.Types.Config ( BuildConfig (..), BuildOpts (..), Config (..) - , ConfigException (..), ConfigPrettyException (..) - , HasConfig (..), ParseAbsolutePathException (..) - , Project (..), ProjectAndConfigMonoid (..) + , HasConfig (..), Project (..), ProjectAndConfigMonoid (..) , ProjectConfig (..), askLatestSnapshotUrl, configProjectRoot - , packageIndicesWarning, parseProjectAndConfigMonoid - , platformOnlyRelDir, stackRootL, workDirL + , parseProjectAndConfigMonoid, platformOnlyRelDir, stackRootL + , workDirL ) +import Stack.Types.Config.Exception + ( ConfigException (..), ConfigPrettyException (..) + , ParseAbsolutePathException (..), packageIndicesWarning ) import Stack.Types.ConfigMonoid ( ConfigMonoid (..), parseConfigMonoid ) import Stack.Types.Docker ( DockerOptsMonoid (..), dockerEnable ) diff --git a/src/Stack/Init.hs b/src/Stack/Init.hs index f8237ca181..b051b1954e 100644 --- a/src/Stack/Init.hs +++ b/src/Stack/Init.hs @@ -47,10 +47,8 @@ import Stack.Runners ( ShouldReexec (..), withConfig, withGlobalProject ) import Stack.SourceMap ( SnapshotCandidate, loadProjectSnapshotCandidate ) -import Stack.Types.Config - ( ConfigPrettyException (..), HasConfig, HasGHCVariant - , Project (..) - ) +import Stack.Types.Config ( HasConfig, HasGHCVariant, Project (..) ) +import Stack.Types.Config.Exception ( ConfigPrettyException (..) ) import Stack.Types.GlobalOpts ( GlobalOpts (..) ) import Stack.Types.Runner (Runner, globalOptsL ) import Stack.Types.Resolver ( AbstractResolver, Snapshots (..) ) diff --git a/src/Stack/Lock.hs b/src/Stack/Lock.hs index b9ff61f8ee..fc8e1d8c09 100644 --- a/src/Stack/Lock.hs +++ b/src/Stack/Lock.hs @@ -24,7 +24,7 @@ import Path.Extended ( addExtension ) import Path.IO ( doesFileExist ) import Stack.Prelude import Stack.SourceMap ( snapToDepPackage ) -import Stack.Types.Config ( ConfigPrettyException (..) ) +import Stack.Types.Config.Exception ( ConfigPrettyException (..) ) import Stack.Types.LockFileBehavior ( LockFileBehavior (..) ) import Stack.Types.Runner ( HasRunner, lockFileBehaviorL, rslInLogL ) import Stack.Types.SourceMap ( DepPackage, SMWanted ) diff --git a/src/Stack/Types/Config.hs b/src/Stack/Types/Config.hs index 2e12e729d5..80c996295f 100644 --- a/src/Stack/Types/Config.hs +++ b/src/Stack/Types/Config.hs @@ -38,12 +38,6 @@ module Stack.Types.Config -- ** GHCVariant & HasGHCVariant , HasGHCVariant (..) -- * Details - -- ** ConfigException - , HpackExecutable (..) - , ConfigException (..) - , ConfigPrettyException (..) - , ParseAbsolutePathException (..) - , packageIndicesWarning -- ** EnvSettings , EnvSettings (..) , minimalEnvSettings @@ -104,11 +98,9 @@ import Pantry.Internal.AesonExtended ) import qualified Data.ByteArray.Encoding as Mem ( Base(Base16), convertToBase ) import qualified Data.ByteString.Char8 as S8 -import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T -import Data.Yaml ( ParseException ) import qualified Data.Yaml as Yaml import Distribution.PackageDescription ( GenericPackageDescription ) import qualified Distribution.PackageDescription as C @@ -120,8 +112,8 @@ import Options.Applicative ( ReadM ) import qualified Options.Applicative.Types as OA import Pantry.Internal ( Storage ) import Path - ( (), dirname, filename, parent, parseAbsDir, parseAbsFile - , parseRelDir, parseRelFile, reldir, relfile + ( (), parent, parseAbsDir, parseAbsFile, parseRelDir + , parseRelFile, reldir, relfile ) import RIO.Process ( HasProcessContext (..), ProcessContext ) import Stack.Constants ( bindirSuffix, docDirSuffix, osIsWindows ) @@ -134,9 +126,7 @@ import Stack.Types.Compiler ) import Stack.Types.CompilerBuild ( CompilerBuild ) import Stack.Types.ConfigMonoid - ( ConfigMonoid (..), configMonoidAllowDifferentUserName - , configMonoidGHCVariantName, configMonoidSystemGHCName - , parseConfigMonoidObject) + ( ConfigMonoid (..), parseConfigMonoidObject) import Stack.Types.Docker ( DockerOpts ) import Stack.Types.DumpLogs ( DumpLogs ) import Stack.Types.GHCVariant ( GHCVariant (..) ) @@ -155,271 +145,11 @@ import Stack.Types.SourceMap , SMWanted (..) ) import Stack.Types.TemplateName ( TemplateName ) -import Stack.Types.Version - ( VersionCheck (..), VersionRange, stackVersion - , versionRangeText - ) +import Stack.Types.Version ( VersionCheck (..), VersionRange ) -- Re-exports import Stack.Types.Config.Build as X --- | Type representing exceptions thrown by functions exported by the --- "Stack.Config" module. -data ConfigException - = ParseCustomSnapshotException Text ParseException - | NoProjectConfigFound (Path Abs Dir) (Maybe Text) - | UnexpectedArchiveContents [Path Abs Dir] [Path Abs File] - | UnableToExtractArchive Text (Path Abs File) - | BadStackVersionException VersionRange - | NoSuchDirectory FilePath - | ParseGHCVariantException String - | BadStackRoot (Path Abs Dir) - | Won'tCreateStackRootInDirectoryOwnedByDifferentUser - (Path Abs Dir) - (Path Abs Dir) - -- ^ @$STACK_ROOT@, parent dir - | UserDoesn'tOwnDirectory (Path Abs Dir) - | ManualGHCVariantSettingsAreIncompatibleWithSystemGHC - | NixRequiresSystemGhc - | NoResolverWhenUsingNoProject - | NoLTSWithMajorVersion Int - | NoLTSFound - deriving (Show, Typeable) - -instance Exception ConfigException where - displayException (ParseCustomSnapshotException url exception) = concat - [ "Error: [S-8981]\n" - , "Could not parse '" - , T.unpack url - , "':\n" - , Yaml.prettyPrintParseException exception - , "\nSee https://docs.haskellstack.org/en/stable/custom_snapshot/" - ] - displayException (NoProjectConfigFound dir mcmd) = concat - [ "Error: [S-2206]\n" - , "Unable to find a stack.yaml file in the current directory (" - , toFilePath dir - , ") or its ancestors" - , case mcmd of - Nothing -> "" - Just cmd -> "\nRecommended action: stack " ++ T.unpack cmd - ] - displayException (UnexpectedArchiveContents dirs files) = concat - [ "Error: [S-4964]\n" - , "When unpacking an archive specified in your stack.yaml file, " - , "did not find expected contents. Expected: a single directory. Found: " - , show ( map (toFilePath . dirname) dirs - , map (toFilePath . filename) files - ) - ] - displayException (UnableToExtractArchive url file) = concat - [ "Error: [S-2040]\n" - , "Archive extraction failed. Tarballs and zip archives are supported, \ - \couldn't handle the following URL, " - , T.unpack url - , " downloaded to the file " - , toFilePath $ filename file - ] - displayException (BadStackVersionException requiredRange) = concat - [ "Error: [S-1641]\n" - , "The version of Stack you are using (" - , show stackVersion - , ") is outside the required\n" - ,"version range specified in stack.yaml (" - , T.unpack (versionRangeText requiredRange) - , ").\n" - , "You can upgrade Stack by running:\n\n" - , "stack upgrade" - ] - displayException (NoSuchDirectory dir) = concat - [ "Error: [S-8773]\n" - , "No directory could be located matching the supplied path: " - , dir - ] - displayException (ParseGHCVariantException v) = concat - [ "Error: [S-3938]\n" - , "Invalid ghc-variant value: " - , v - ] - displayException (BadStackRoot stackRoot) = concat - [ "Error: [S-8530]\n" - , "Invalid Stack root: '" - , toFilePath stackRoot - , "'. Please provide a valid absolute path." - ] - displayException (Won'tCreateStackRootInDirectoryOwnedByDifferentUser envStackRoot parentDir) = concat - [ "Error: [S-7613]\n" - , "Preventing creation of Stack root '" - , toFilePath envStackRoot - , "'. Parent directory '" - , toFilePath parentDir - , "' is owned by someone else." - ] - displayException (UserDoesn'tOwnDirectory dir) = concat - [ "Error: [S-8707]\n" - , "You are not the owner of '" - , toFilePath dir - , "'. Aborting to protect file permissions." - , "\nRetry with '--" - , T.unpack configMonoidAllowDifferentUserName - , "' to disable this precaution." - ] - displayException ManualGHCVariantSettingsAreIncompatibleWithSystemGHC = T.unpack $ T.concat - [ "Error: [S-3605]\n" - , "Stack can only control the " - , configMonoidGHCVariantName - , " of its own GHC installations. Please use '--no-" - , configMonoidSystemGHCName - , "'." - ] - displayException NixRequiresSystemGhc = T.unpack $ T.concat - [ "Error: [S-6816]\n" - , "Stack's Nix integration is incompatible with '--no-system-ghc'. " - , "Please use '--" - , configMonoidSystemGHCName - , "' or disable the Nix integration." - ] - displayException NoResolverWhenUsingNoProject = - "Error: [S-5027]\n" - ++ "When using the script command, you must provide a resolver argument" - displayException (NoLTSWithMajorVersion n) = concat - [ "Error: [S-3803]\n" - , "No LTS release found with major version " - , show n - , "." - ] - displayException NoLTSFound = - "Error: [S-5472]\n" - ++ "No LTS releases found." - --- | Type representing \'pretty\' exceptions thrown by functions exported by the --- "Stack.Config" module. -data ConfigPrettyException - = ParseConfigFileException !(Path Abs File) !ParseException - | StackWorkEnvNotRelativeDir !String - | NoMatchingSnapshot !(NonEmpty SnapName) - | ResolverMismatch !RawSnapshotLocation String - | ResolverPartial !RawSnapshotLocation !String - | MultiplePackageIndices [PackageIndexConfig] - | DuplicateLocalPackageNames ![(PackageName, [PackageLocation])] - deriving (Show, Typeable) - -instance Pretty ConfigPrettyException where - pretty (ParseConfigFileException configFile exception) = - "[S-6602]" - <> line - <> fillSep - [ flow "Stack could not load and parse" - , pretty configFile - , flow "as a YAML configuraton file." - ] - <> blankLine - <> flow "While loading and parsing, Stack encountered the following \ - \error:" - <> blankLine - <> string (Yaml.prettyPrintParseException exception) - <> blankLine - <> fillSep - [ flow "For help about the content of Stack's YAML configuration \ - \files, see (for the most recent release of Stack)" - , style - Url - "http://docs.haskellstack.org/en/stable/yaml_configuration/" - <> "." - ] - pretty (StackWorkEnvNotRelativeDir x) = - "[S-7462]" - <> line - <> flow "Stack failed to interpret the value of the STACK_WORK \ - \environment variable as a valid relative path to a directory. \ - \Stack will not accept an absolute path. A path containing a \ - \.. (parent directory) component is not valid." - <> blankLine - <> fillSep - [ flow "If set, Stack expects the value to identify the location \ - \of Stack's work directory, relative to the root directory \ - \of the project or package. Stack encountered the value:" - , style Error (fromString x) <> "." - ] - pretty (NoMatchingSnapshot names) = - "[S-1833]" - <> line - <> flow "None of the following snapshots provides a compiler matching \ - \your package(s):" - <> line - <> bulletedList (map (fromString . show) (NonEmpty.toList names)) - <> blankLine - <> resolveOptions - pretty (ResolverMismatch resolver errDesc) = - "[S-6395]" - <> line - <> fillSep - [ "Snapshot" - , style Url (pretty $ PrettyRawSnapshotLocation resolver) - , flow "does not have a matching compiler to build some or all of \ - \your package(s)." - ] - <> blankLine - <> indent 4 (string errDesc) - <> line - <> resolveOptions - pretty (ResolverPartial resolver errDesc) = - "[S-2422]" - <> line - <> fillSep - [ "Snapshot" - , style Url (pretty $ PrettyRawSnapshotLocation resolver) - , flow "does not have all the packages to match your requirements." - ] - <> blankLine - <> indent 4 (string errDesc) - <> line - <> resolveOptions - pretty (MultiplePackageIndices pics) = - "[S-3251]" - <> line - <> fillSep - [ flow "When using the" - , style Shell "package-indices" - , flow "key to override the default package index, you must \ - \provide exactly one value, received:" - , bulletedList (map (string . show) pics) - ] - <> blankLine - <> packageIndicesWarning - pretty (DuplicateLocalPackageNames pairs) = - "[S-5470]" - <> line - <> fillSep - [ flow "The same package name is used in more than one local package or" - , style Shell "extra-deps" <> "." - ] - <> mconcat (map go pairs) - where - go (name, dirs) = - blankLine - <> fillSep - [ style Error (fromString $ packageNameString name) - , flow "used in:" - ] - <> line - <> bulletedList (map (fromString . T.unpack . textDisplay) dirs) - -instance Exception ConfigPrettyException - -data ParseAbsolutePathException - = ParseAbsolutePathException String String - deriving (Show, Typeable) - -instance Exception ParseAbsolutePathException where - displayException (ParseAbsolutePathException envVar dir) = concat - [ "Error: [S-9437]\n" - , "Failed to parse " - , envVar - , " environment variable (expected absolute directory): " - , dir - ] - -- | The top-level Stackage configuration. data Config = Config { configWorkDir :: !(Path Rel Dir) @@ -739,32 +469,6 @@ instance FromJSON (WithJSONWarnings Curator) where <*> fmap (Set.map unCabalString) (o ..:? "skip-haddock" ..!= mempty) <*> fmap (Set.map unCabalString) (o ..:? "expect-haddock-failure" ..!= mempty) -packageIndicesWarning :: StyleDoc -packageIndicesWarning = - fillSep - [ "The" - , style Shell "package-indices" - , flow "key is deprecated in favour of" - , style Shell "package-index" <> "." - ] - -resolveOptions :: StyleDoc -resolveOptions = - flow "This may be resolved by:" - <> line - <> bulletedList - [ fillSep - [ "Using" - , style Shell "--omit-packages" - , "to exclude mismatching package(s)." - ] - , fillSep - [ "Using" - , style Shell "--resolver" - , "to specify a matching snapshot/resolver." - ] - ] - -- | Get the URL to request the information on the latest snapshots askLatestSnapshotUrl :: (MonadReader env m, HasConfig env) => m Text askLatestSnapshotUrl = view $ configL.to configLatestSnapshot diff --git a/src/Stack/Types/Config/Exception.hs b/src/Stack/Types/Config/Exception.hs new file mode 100644 index 0000000000..4e70e7613b --- /dev/null +++ b/src/Stack/Types/Config/Exception.hs @@ -0,0 +1,308 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE GADTs #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeFamilies #-} + +module Stack.Types.Config.Exception + ( ConfigException (..) + , ConfigPrettyException (..) + , ParseAbsolutePathException (..) + , packageIndicesWarning + ) where + +import qualified Data.List.NonEmpty as NonEmpty +import qualified Data.Text as T +import Data.Yaml ( ParseException ) +import qualified Data.Yaml as Yaml +import Path( dirname, filename ) +import Stack.Prelude +import Stack.Types.ConfigMonoid + ( configMonoidAllowDifferentUserName + , configMonoidGHCVariantName, configMonoidSystemGHCName + ) +import Stack.Types.Version + ( VersionRange, stackVersion, versionRangeText ) + +-- | Type representing exceptions thrown by functions exported by the +-- "Stack.Config" module. +data ConfigException + = ParseCustomSnapshotException Text ParseException + | NoProjectConfigFound (Path Abs Dir) (Maybe Text) + | UnexpectedArchiveContents [Path Abs Dir] [Path Abs File] + | UnableToExtractArchive Text (Path Abs File) + | BadStackVersionException VersionRange + | NoSuchDirectory FilePath + | ParseGHCVariantException String + | BadStackRoot (Path Abs Dir) + | Won'tCreateStackRootInDirectoryOwnedByDifferentUser + (Path Abs Dir) + (Path Abs Dir) + -- ^ @$STACK_ROOT@, parent dir + | UserDoesn'tOwnDirectory (Path Abs Dir) + | ManualGHCVariantSettingsAreIncompatibleWithSystemGHC + | NixRequiresSystemGhc + | NoResolverWhenUsingNoProject + | NoLTSWithMajorVersion Int + | NoLTSFound + deriving (Show, Typeable) + +instance Exception ConfigException where + displayException (ParseCustomSnapshotException url exception) = concat + [ "Error: [S-8981]\n" + , "Could not parse '" + , T.unpack url + , "':\n" + , Yaml.prettyPrintParseException exception + , "\nSee https://docs.haskellstack.org/en/stable/custom_snapshot/" + ] + displayException (NoProjectConfigFound dir mcmd) = concat + [ "Error: [S-2206]\n" + , "Unable to find a stack.yaml file in the current directory (" + , toFilePath dir + , ") or its ancestors" + , case mcmd of + Nothing -> "" + Just cmd -> "\nRecommended action: stack " ++ T.unpack cmd + ] + displayException (UnexpectedArchiveContents dirs files) = concat + [ "Error: [S-4964]\n" + , "When unpacking an archive specified in your stack.yaml file, " + , "did not find expected contents. Expected: a single directory. Found: " + , show ( map (toFilePath . dirname) dirs + , map (toFilePath . filename) files + ) + ] + displayException (UnableToExtractArchive url file) = concat + [ "Error: [S-2040]\n" + , "Archive extraction failed. Tarballs and zip archives are supported, \ + \couldn't handle the following URL, " + , T.unpack url + , " downloaded to the file " + , toFilePath $ filename file + ] + displayException (BadStackVersionException requiredRange) = concat + [ "Error: [S-1641]\n" + , "The version of Stack you are using (" + , show stackVersion + , ") is outside the required\n" + ,"version range specified in stack.yaml (" + , T.unpack (versionRangeText requiredRange) + , ").\n" + , "You can upgrade Stack by running:\n\n" + , "stack upgrade" + ] + displayException (NoSuchDirectory dir) = concat + [ "Error: [S-8773]\n" + , "No directory could be located matching the supplied path: " + , dir + ] + displayException (ParseGHCVariantException v) = concat + [ "Error: [S-3938]\n" + , "Invalid ghc-variant value: " + , v + ] + displayException (BadStackRoot stackRoot) = concat + [ "Error: [S-8530]\n" + , "Invalid Stack root: '" + , toFilePath stackRoot + , "'. Please provide a valid absolute path." + ] + displayException (Won'tCreateStackRootInDirectoryOwnedByDifferentUser envStackRoot parentDir) = concat + [ "Error: [S-7613]\n" + , "Preventing creation of Stack root '" + , toFilePath envStackRoot + , "'. Parent directory '" + , toFilePath parentDir + , "' is owned by someone else." + ] + displayException (UserDoesn'tOwnDirectory dir) = concat + [ "Error: [S-8707]\n" + , "You are not the owner of '" + , toFilePath dir + , "'. Aborting to protect file permissions." + , "\nRetry with '--" + , T.unpack configMonoidAllowDifferentUserName + , "' to disable this precaution." + ] + displayException ManualGHCVariantSettingsAreIncompatibleWithSystemGHC = T.unpack $ T.concat + [ "Error: [S-3605]\n" + , "Stack can only control the " + , configMonoidGHCVariantName + , " of its own GHC installations. Please use '--no-" + , configMonoidSystemGHCName + , "'." + ] + displayException NixRequiresSystemGhc = T.unpack $ T.concat + [ "Error: [S-6816]\n" + , "Stack's Nix integration is incompatible with '--no-system-ghc'. " + , "Please use '--" + , configMonoidSystemGHCName + , "' or disable the Nix integration." + ] + displayException NoResolverWhenUsingNoProject = + "Error: [S-5027]\n" + ++ "When using the script command, you must provide a resolver argument" + displayException (NoLTSWithMajorVersion n) = concat + [ "Error: [S-3803]\n" + , "No LTS release found with major version " + , show n + , "." + ] + displayException NoLTSFound = + "Error: [S-5472]\n" + ++ "No LTS releases found." + +-- | Type representing \'pretty\' exceptions thrown by functions exported by the +-- "Stack.Config" module. +data ConfigPrettyException + = ParseConfigFileException !(Path Abs File) !ParseException + | StackWorkEnvNotRelativeDir !String + | NoMatchingSnapshot !(NonEmpty SnapName) + | ResolverMismatch !RawSnapshotLocation String + | ResolverPartial !RawSnapshotLocation !String + | MultiplePackageIndices [PackageIndexConfig] + | DuplicateLocalPackageNames ![(PackageName, [PackageLocation])] + deriving (Show, Typeable) + +instance Pretty ConfigPrettyException where + pretty (ParseConfigFileException configFile exception) = + "[S-6602]" + <> line + <> fillSep + [ flow "Stack could not load and parse" + , pretty configFile + , flow "as a YAML configuraton file." + ] + <> blankLine + <> flow "While loading and parsing, Stack encountered the following \ + \error:" + <> blankLine + <> string (Yaml.prettyPrintParseException exception) + <> blankLine + <> fillSep + [ flow "For help about the content of Stack's YAML configuration \ + \files, see (for the most recent release of Stack)" + , style + Url + "http://docs.haskellstack.org/en/stable/yaml_configuration/" + <> "." + ] + pretty (StackWorkEnvNotRelativeDir x) = + "[S-7462]" + <> line + <> flow "Stack failed to interpret the value of the STACK_WORK \ + \environment variable as a valid relative path to a directory. \ + \Stack will not accept an absolute path. A path containing a \ + \.. (parent directory) component is not valid." + <> blankLine + <> fillSep + [ flow "If set, Stack expects the value to identify the location \ + \of Stack's work directory, relative to the root directory \ + \of the project or package. Stack encountered the value:" + , style Error (fromString x) <> "." + ] + pretty (NoMatchingSnapshot names) = + "[S-1833]" + <> line + <> flow "None of the following snapshots provides a compiler matching \ + \your package(s):" + <> line + <> bulletedList (map (fromString . show) (NonEmpty.toList names)) + <> blankLine + <> resolveOptions + pretty (ResolverMismatch resolver errDesc) = + "[S-6395]" + <> line + <> fillSep + [ "Snapshot" + , style Url (pretty $ PrettyRawSnapshotLocation resolver) + , flow "does not have a matching compiler to build some or all of \ + \your package(s)." + ] + <> blankLine + <> indent 4 (string errDesc) + <> line + <> resolveOptions + pretty (ResolverPartial resolver errDesc) = + "[S-2422]" + <> line + <> fillSep + [ "Snapshot" + , style Url (pretty $ PrettyRawSnapshotLocation resolver) + , flow "does not have all the packages to match your requirements." + ] + <> blankLine + <> indent 4 (string errDesc) + <> line + <> resolveOptions + pretty (MultiplePackageIndices pics) = + "[S-3251]" + <> line + <> fillSep + [ flow "When using the" + , style Shell "package-indices" + , flow "key to override the default package index, you must \ + \provide exactly one value, received:" + , bulletedList (map (string . show) pics) + ] + <> blankLine + <> packageIndicesWarning + pretty (DuplicateLocalPackageNames pairs) = + "[S-5470]" + <> line + <> fillSep + [ flow "The same package name is used in more than one local package or" + , style Shell "extra-deps" <> "." + ] + <> mconcat (map go pairs) + where + go (name, dirs) = + blankLine + <> fillSep + [ style Error (fromString $ packageNameString name) + , flow "used in:" + ] + <> line + <> bulletedList (map (fromString . T.unpack . textDisplay) dirs) + +instance Exception ConfigPrettyException + +data ParseAbsolutePathException + = ParseAbsolutePathException String String + deriving (Show, Typeable) + +instance Exception ParseAbsolutePathException where + displayException (ParseAbsolutePathException envVar dir) = concat + [ "Error: [S-9437]\n" + , "Failed to parse " + , envVar + , " environment variable (expected absolute directory): " + , dir + ] + +packageIndicesWarning :: StyleDoc +packageIndicesWarning = + fillSep + [ "The" + , style Shell "package-indices" + , flow "key is deprecated in favour of" + , style Shell "package-index" <> "." + ] + +resolveOptions :: StyleDoc +resolveOptions = + flow "This may be resolved by:" + <> line + <> bulletedList + [ fillSep + [ "Using" + , style Shell "--omit-packages" + , "to exclude mismatching package(s)." + ] + , fillSep + [ "Using" + , style Shell "--resolver" + , "to specify a matching snapshot/resolver." + ] + ] diff --git a/stack.cabal b/stack.cabal index 15fb18b267..e13cded5a8 100644 --- a/stack.cabal +++ b/stack.cabal @@ -251,6 +251,7 @@ library Stack.Types.Compiler Stack.Types.Config Stack.Types.Config.Build + Stack.Types.Config.Exception Stack.Types.ConfigMonoid Stack.Types.Docker Stack.Types.DockerEntrypoint