Skip to content

Commit 98b36dd

Browse files
committed
Re commercialhaskell#5955 Use different file types in data constructor
1 parent 1c078dc commit 98b36dd

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/Stack/New.hs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE ConstraintKinds #-}
3-
{-# LANGUAGE DeriveDataTypeable #-}
4-
{-# LANGUAGE FlexibleContexts #-}
5-
{-# LANGUAGE OverloadedStrings #-}
6-
{-# LANGUAGE ScopedTypeVariables #-}
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE ConstraintKinds #-}
3+
{-# LANGUAGE DeriveDataTypeable #-}
4+
{-# LANGUAGE ExistentialQuantification #-}
5+
{-# LANGUAGE FlexibleContexts #-}
6+
{-# LANGUAGE OverloadedStrings #-}
7+
{-# LANGUAGE ScopedTypeVariables #-}
8+
{-# LANGUAGE StandaloneDeriving #-}
79

810
-- | Create new a new project directory populated with a basic working
911
-- project.
@@ -59,14 +61,16 @@ import Text.ProjectTemplate
5961
data NewPrettyException
6062
= ProjectDirAlreadyExists !String !(Path Abs Dir)
6163
| DownloadTemplateFailed !Text !String !VerifiedDownloadException
62-
| LoadTemplateFailed !TemplateName !FilePath
63-
| ExtractTemplateFailed !TemplateName !FilePath !String
64+
| forall b. LoadTemplateFailed !TemplateName !(Path b File)
65+
| forall b. ExtractTemplateFailed !TemplateName !(Path b File) !String
6466
| TemplateInvalid !TemplateName !StyleDoc
6567
| MagicPackageNameInvalid !String
6668
| AttemptedOverwrites !Text ![Path Abs File]
6769
| DownloadTemplatesHelpFailed !HttpException
6870
| TemplatesHelpEncodingInvalid !String !UnicodeException
69-
deriving (Show, Typeable)
71+
deriving Typeable
72+
73+
deriving instance Show NewPrettyException
7074

7175
instance Pretty NewPrettyException where
7276
pretty (ProjectDirAlreadyExists name path) =
@@ -133,7 +137,7 @@ instance Pretty NewPrettyException where
133137
[ flow "Stack failed to load the downloaded template"
134138
, style Current (fromString $ T.unpack $ templateName name)
135139
, "from"
136-
, style File (fromString path) <> "."
140+
, style File (pretty path) <> "."
137141
]
138142
pretty (ExtractTemplateFailed name path err) =
139143
"[S-9582]"
@@ -142,7 +146,7 @@ instance Pretty NewPrettyException where
142146
[ flow "Stack failed to extract the loaded template"
143147
, style Current (fromString $ T.unpack $ templateName name)
144148
, "at"
145-
, style File (fromString path) <> "."
149+
, style File (pretty path) <> "."
146150
]
147151
<> blankLine
148152
<> flow "While extracting, Stack encountered the following exception:"
@@ -346,11 +350,11 @@ loadTemplate name logIt = do
346350
bs <- readFileBinary (toFilePath path) --readFileUtf8 (toFilePath path)
347351
case extract bs of
348352
Left err -> throwM $ PrettyException $
349-
ExtractTemplateFailed name (toFilePath path) err
353+
ExtractTemplateFailed name path err
350354
Right template ->
351355
pure template
352356
else throwM $ PrettyException $
353-
LoadTemplateFailed name (toFilePath path)
357+
LoadTemplateFailed name path
354358
relSettings :: String -> Maybe TemplateDownloadSettings
355359
relSettings req = do
356360
rtp <- parseRepoPathWithService defaultRepoService (T.pack req)

0 commit comments

Comments
 (0)