@@ -31,20 +31,28 @@ import Stack.Types.Config
31
31
import Stack.Types.SourceMap
32
32
( DepPackage , SMWanted )
33
33
34
- -- | Type representing exceptions thrown by functions exported by the
34
+ -- | Type representing \'pretty\' exceptions thrown by functions exported by the
35
35
-- "Stack.Lock" module.
36
- data LockException
36
+ data LockPrettyException
37
37
= WritingLockFileError (Path Abs File ) Locked
38
38
deriving (Show , Typeable )
39
39
40
- instance Exception LockException where
41
- displayException (WritingLockFileError lockFile newLocked) = unlines
42
- [ " Error: [S-1353]"
43
- , " You indicated that Stack should error out on writing a lock file"
44
- , " Stack just tried to write the following lock file contents to "
45
- ++ toFilePath lockFile
46
- , T. unpack $ decodeUtf8With lenientDecode $ Yaml. encode newLocked
47
- ]
40
+ instance Pretty LockPrettyException where
41
+ pretty (WritingLockFileError lockFile newLocked) =
42
+ " [S-1353]"
43
+ <> line
44
+ <> flow " Stack is configured to report an error on writing a lock file."
45
+ <> blankLine
46
+ <> fillSep
47
+ [ flow " Stack just tried to write the following lock file content to"
48
+ , pretty lockFile <> " :"
49
+ ]
50
+ <> blankLine
51
+ <> string newLocked'
52
+ where
53
+ newLocked' = T. unpack . decodeUtf8With lenientDecode $ Yaml. encode newLocked
54
+
55
+ instance Exception LockPrettyException
48
56
49
57
data LockedLocation a b = LockedLocation
50
58
{ llOriginal :: a
@@ -171,7 +179,8 @@ lockCachedWanted stackFile resolver fillWanted = do
171
179
writeBinaryFileAtomic lockFile $
172
180
header <>
173
181
byteString (Yaml. encode newLocked)
174
- LFBErrorOnWrite -> throwIO $ WritingLockFileError lockFile newLocked
182
+ LFBErrorOnWrite ->
183
+ throwIO $ PrettyException $ WritingLockFileError lockFile newLocked
175
184
LFBIgnore -> pure ()
176
185
LFBReadOnly -> pure ()
177
186
pure wanted
0 commit comments