Skip to content

Commit 6610a08

Browse files
committed
Slightly nicer error displays
1 parent e1ab0ed commit 6610a08

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

ext-common/Ext/TypeHash.hs

+15-13
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,12 @@ calculateHashes pkg modul targetTypes canonical interfaces inDebug = do
8787

8888
if List.length errors > 0
8989
then
90-
let
91-
-- !x = onlyWhen inDebug $ formatHaskellValue "diffHasErrors:" typediffs :: IO ()
92-
93-
notifyWarnings =
94-
if List.length warnings > 0 then
95-
[ D.reflow $ "Warning: also, a number of types outside Types.elm are referenced, see `lamdera check` for more info." ]
96-
else
97-
[]
98-
in
9990
Left $
10091
Exit.BuildLamderaProblem "WIRE ISSUES"
101-
"I ran into the following problems when checking Lamdera core types:"
92+
"I found one or more Route Modules with Data types that contain functions."
10293
(formattedErrors ++
10394
[ D.reflow "See <https://dashboard.lamdera.app/docs/wire> for more info."
104-
] ++ notifyWarnings)
95+
])
10596

10697
else do
10798
Right (hashes, warnings)
@@ -546,13 +537,24 @@ diffableTypeErrors dtype =
546537
case dtype of
547538
DRecord fields ->
548539
fields
549-
& fmap (\(n, tipe) -> diffableTypeErrors tipe)
540+
& fmap (\(n, tipe) -> do
541+
let errors = diffableTypeErrors tipe
542+
case errors of
543+
[] -> []
544+
xs -> errors & fmap (\err -> "{ " <> n <> " } " <> err )
545+
)
550546
& List.concat
551547

552548
DCustom name constructors ->
553549
constructors
554550
& fmap (\(n, params) ->
555-
fmap diffableTypeErrors params
551+
params
552+
& fmap (\param -> do
553+
let errors = diffableTypeErrors param
554+
case errors of
555+
[] -> []
556+
xs -> errors & fmap (\err -> n <> " " <> err)
557+
)
556558
& List.concat
557559
)
558560
& List.concat

extra/Lamdera/Compile.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ makeDev root path = do
8282
absRoot <- Dir.makeAbsolute root
8383

8484
r <- async $
85-
Dir.withCurrentDirectory absRoot $
85+
Dir.withCurrentDirectory absRoot $ do
86+
touch path
8687
Make.run [path] $
8788
Make.Flags
8889
{ _debug = True

test/Test/Ext/ElmPages/Check.hs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
module Test.Ext.ElmPages.Check where
44

5+
import qualified Data.Text as T
6+
57
import EasyTest
68
import Test.Helpers
79

@@ -14,9 +16,13 @@ all = EasyTest.run suite
1416
suite :: Test ()
1517
suite = tests $
1618
[ scope "isWireCompatible" $ do
17-
actual <- catchOutput $
19+
io $ setEnv "LDEBUG" "1"
20+
21+
actual <- catchOutputStdErr $
1822
Lamdera.Compile.makeDev "./test/scenario-elm-pages-incompatible-wire/.elm-pages" "Main.elm"
1923

24+
io $ atomicPutStrLn $ T.unpack actual
25+
2026
expectTextContains actual
2127
"PageData:\\n\\n- must not contain functions"
2228
]

test/Test/Helpers.hs

+9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ module Test.Helpers where
33
import System.Environment (setEnv, unsetEnv, lookupEnv)
44
import System.FilePath ((</>))
55
import Data.Text as T
6+
import qualified Data.Text.Encoding as T
67

78
import EasyTest
89

910
import Lamdera
1011
import Test.Main (captureProcessResult)
12+
import qualified Test.Main
1113

1214

1315
aggressiveCacheClear :: FilePath -> IO ()
@@ -59,3 +61,10 @@ catchOutput action = do
5961
pr <- io $ captureProcessResult action
6062
-- @TODO improve this to actually pull out values
6163
pure $ show_ pr
64+
65+
catchOutputStdErr :: IO () -> Test Text
66+
catchOutputStdErr action = do
67+
-- https://hackage.haskell.org/package/main-tester-0.2.0.1/docs/Test-Main.html
68+
pr <- io $ captureProcessResult action
69+
-- @TODO improve this to actually pull out values
70+
pure $ T.decodeUtf8 $ Test.Main.prStderr pr

0 commit comments

Comments
 (0)