Skip to content

Commit f1dac4c

Browse files
authored
Merge pull request #6039 from commercialhaskell/pretty-1353
2 parents 8042969 + b5cf956 commit f1dac4c

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

doc/maintainers/stack_errors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In connection with considering Stack's support of the
66
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
77
to take stock of the errors that Stack itself can raise, by reference to the
8-
`master` branch of the Stack repository. Last updated: 2022-12-31.
8+
`master` branch of the Stack repository. Last updated: 2023-01-21.
99

1010
* `Main.main`: catches exceptions from action `commandLineHandler`.
1111

@@ -179,7 +179,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
179179
[S-4926] = CouldNotParsePackageSelectors [String]
180180
~~~
181181

182-
- `Stack.Lock.LockException`
182+
- `Stack.Lock.LockPrettyException`
183183

184184
~~~haskell
185185
[S-1353] = WritingLockFileError (Path Abs File) Locked

src/Stack/Lock.hs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,28 @@ import Stack.Types.Config
3131
import Stack.Types.SourceMap
3232
( DepPackage, SMWanted )
3333

34-
-- | Type representing exceptions thrown by functions exported by the
34+
-- | Type representing \'pretty\' exceptions thrown by functions exported by the
3535
-- "Stack.Lock" module.
36-
data LockException
36+
data LockPrettyException
3737
= WritingLockFileError (Path Abs File) Locked
3838
deriving (Show, Typeable)
3939

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
4856

4957
data LockedLocation a b = LockedLocation
5058
{ llOriginal :: a
@@ -171,7 +179,8 @@ lockCachedWanted stackFile resolver fillWanted = do
171179
writeBinaryFileAtomic lockFile $
172180
header <>
173181
byteString (Yaml.encode newLocked)
174-
LFBErrorOnWrite -> throwIO $ WritingLockFileError lockFile newLocked
182+
LFBErrorOnWrite ->
183+
throwIO $ PrettyException $ WritingLockFileError lockFile newLocked
175184
LFBIgnore -> pure ()
176185
LFBReadOnly -> pure ()
177186
pure wanted

0 commit comments

Comments
 (0)