on master help sign in
Replace ELM_HOME with actual value in error messages
commitb0b9b19f65e2427cde2cbaf47cabf3d24149831d authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 10 May 2018, 20:08 (8 years ago) parentf66de6c
8 files changed+48−25
builder/src/Deps/Explorer.hs+4−2 builder/src/Deps/Verify.hs+3−1 builder/src/Elm/PerUserCache.hs+8−2 builder/src/File/IO.hs+3−1 builder/src/Reporting/Exit/Assets.hs+12−6 builder/src/Reporting/Exit/Deps.hs+11−9 builder/src/Reporting/Exit/Install.hs+2−2 ui/terminal/src/Install.hs+5−2
builder/src/Deps/Explorer.hs+4−2
@@ -19,7 +19,7 @@ The goal of this module is to only pay for (1) and pay for (2) as needed.
1919-}
2020
2121
22−import Control.Monad.Except (lift, throwError)
22+import Control.Monad.Except (liftIO, lift, throwError)
2323import Control.Monad.State (StateT, evalStateT, gets, modify)
2424import Data.Map (Map)
2525import qualified Data.Map as Map
@@ -27,6 +27,7 @@ import qualified Data.Map as Map
2727import Elm.Package (Name, Version)
2828
2929import qualified Deps.Get as Get
30+import qualified Elm.PerUserCache as PerUserCache
3031import qualified Elm.Project.Json as Project
3132import Elm.Project.Constraint (Constraint)
3233import qualified Reporting.Exit as Exit
@@ -89,7 +90,8 @@ getVersions name =
8990 return versions
9091
9192 Left _suggestions ->
92− throwError (Exit.Deps (E.CorruptVersionCache name))
93+ do elmHome <- liftIO PerUserCache.getElmHome
94+ throwError (Exit.Deps (E.CorruptVersionCache elmHome name))
9395
9496
9597
builder/src/Deps/Verify.hs+3−1
@@ -19,6 +19,7 @@ import qualified Elm.Compiler.Module as Module
1919import qualified Elm.Compiler.Objects as Obj
2020import qualified Elm.Docs as Docs
2121import Elm.Package (Name, Version)
22+import qualified Elm.PerUserCache as PerUserCache
2223import Elm.Project.Json (Project(..), AppInfo(..), PkgInfo(..))
2324import qualified Json.Encode as Encode
2425
@@ -192,7 +193,8 @@ toInfo _ answer =
192193 return Nothing
193194
194195 Err name version ->
195− throw (E.BuildFailure name version)
196+ do elmHome <- liftIO PerUserCache.getElmHome
197+ throw (E.BuildFailure elmHome name version)
196198
197199
198200ifNotBlocked :: Map Name Answer -> (Map Name PkgInfo -> IO Answer) -> IO Answer
builder/src/Elm/PerUserCache.hs+8−2
@@ -2,6 +2,7 @@
22module Elm.PerUserCache
33 ( getPackageRoot
44 , getReplRoot
5+ , getElmHome
56 )
67 where
78
@@ -29,8 +30,7 @@ getReplRoot =
2930
3031getRoot :: FilePath -> IO FilePath
3132getRoot projectName =
32− do maybeHome <- Env.lookupEnv "ELM_HOME"
33− home <- maybe (Dir.getAppUserDataDirectory "elm") return maybeHome
33+ do home <- getElmHome
3434 let root = home </> version </> projectName
3535 Dir.createDirectoryIfMissing True root
3636 return root
@@ -39,3 +39,9 @@ getRoot projectName =
3939version :: FilePath
4040version =
4141 Pkg.versionToString Compiler.version
42+
43+
44+getElmHome :: IO FilePath
45+getElmHome =
46+ do maybeHome <- Env.lookupEnv "ELM_HOME"
47+ maybe (Dir.getAppUserDataDirectory "elm") return maybeHome
builder/src/File/IO.hs+3−1
@@ -30,6 +30,7 @@ import qualified System.FilePath as FP
3030import qualified System.IO as IO
3131import System.IO.Error (ioeGetErrorType, annotateIOError, modifyIOError)
3232
33+import qualified Elm.PerUserCache as PerUserCache
3334import qualified Reporting.Exit as Exit
3435import qualified Reporting.Exit.Assets as E
3536import qualified Reporting.Task as Task
@@ -64,7 +65,8 @@ readBinary path =
6465
6566throwCorruptBinary :: FilePath -> Task.Task a
6667throwCorruptBinary filePath =
67− Task.throw (Exit.Assets (E.CorruptBinary filePath))
68+ do elmHome <- liftIO PerUserCache.getElmHome
69+ Task.throw (Exit.Assets (E.CorruptBinary elmHome filePath))
6870
6971
7072
builder/src/Reporting/Exit/Assets.hs+12−6
@@ -25,7 +25,7 @@ data Exit
2525 = BadElmJson ElmJsonProblem
2626 | CorruptElmJson Pkg.Name Pkg.Version
2727 | CorruptDocumentation Pkg.Name Pkg.Version
28− | CorruptBinary FilePath
28+ | CorruptBinary FilePath FilePath
2929
3030
3131
@@ -51,13 +51,19 @@ toReport exit =
5151 CorruptDocumentation pkg vsn ->
5252 corruptJsonToReport "docs.json" pkg vsn
5353
54− CorruptBinary path ->
54+ CorruptBinary elmHome path ->
5555 Help.report "CORRUPT BINARY" (Just path)
5656 ("The binary data at " ++ path ++ " is corrupt.")
57− [ D.reflow $
58− "Maybe a program is modifying your elm-stuff/ or ELM_HOME\
59− \ directory in unexpected ways? Both of those are just caches, so\
60− \ you can try deleting them and they will be rebuilt from scratch."
57+ [ D.reflow "Elm caches build artifacts in the following directories:"
58+ , D.dullyellow $ D.indent 4 $ D.vcat $
59+ [ D.fromString elmHome
60+ , "elm-stuff/"
61+ ]
62+ , D.reflow
63+ "Maybe you recently installed a command line tool or editor plugin that messes\
64+ \ with them? They definitely should not be doing that, but you never know! So\
65+ \ maybe try deleting them? Everything will be rebuilt from scratch. This may\
66+ \ help reveal the corrupting influence."
6167 ]
6268
6369 BadElmJson problem ->
builder/src/Reporting/Exit/Deps.hs+11−9
@@ -19,13 +19,13 @@ import qualified Reporting.Exit.Help as Help
1919
2020
2121data Exit
22− = CorruptVersionCache Pkg.Name
22+ = CorruptVersionCache FilePath Pkg.Name
2323 | PackageNotFound Pkg.Name [Pkg.Name]
2424 -- verify
2525 | AppBadElm Pkg.Version
2626 | PkgBadElm Con.Constraint
2727 | BadDeps
28− | BuildFailure Pkg.Name Pkg.Version
28+ | BuildFailure FilePath Pkg.Name Pkg.Version
2929
3030
3131
@@ -35,13 +35,13 @@ data Exit
3535toReport :: Exit -> Help.Report
3636toReport exit =
3737 case exit of
38− CorruptVersionCache pkg ->
38+ CorruptVersionCache elmHome pkg ->
3939 Help.report "CORRUPT CACHE" Nothing
4040 ( "I ran into an unknown package while exploring dependencies:"
4141 )
4242 [ D.indent 4 $ D.dullyellow $ D.fromString $ Pkg.toString pkg
4343 , D.reflow $
44− "This suggests that your ELM_HOME directory has been corrupted.\
44+ "This suggests that your " ++ elmHome ++ " directory has been corrupted.\
4545 \ Maybe some program is messing with it? It is just cached files,\
4646 \ so you can delete it and see if that fixes the issue."
4747 ]
@@ -94,11 +94,13 @@ toReport exit =
9494 \ you are running into something that seems trickier than this."
9595 ]
9696
97− BuildFailure pkg vsn ->
97+ BuildFailure elmHome pkg vsn ->
9898 Help.report "CORRUPT DEPENDENCY" Nothing
9999 "I ran into a problem while building the following package:"
100− [ D.indent 4 $ D.dullyellow $ D.fromString $ Pkg.toString pkg ++ " " ++ Pkg.versionToString vsn
101− , D.reflow $
102− "This probably means the downloaded files got corrupted somehow.\
103− \ Maybe try deleting your ELM_HOME and see if that resolves the issue?"
100+ [ D.indent 4 $ D.red $ D.fromString $ Pkg.toString pkg ++ " " ++ Pkg.versionToString vsn
101+ , D.fillSep
102+ ["This","probably","means","the","downloaded","files","got","corrupted","somehow."
103+ ,"Try","deleting",D.dullyellow (D.fromString elmHome),"(a","directory","for"
104+ ,"caching","build","artifacts)","and","see","if","that","resolves","the","issue."
105+ ]
104106 ]
builder/src/Reporting/Exit/Install.hs+2−2
@@ -28,7 +28,7 @@ data Exit
2828toReport :: Exit -> Help.Report
2929toReport exit =
3030 case exit of
31− NoArgs cacheDir ->
31+ NoArgs elmHome ->
3232 Help.report "INSTALL WHAT?" Nothing
3333 "I am expecting commands like:"
3434 [ D.green $ D.indent 4 $ D.vcat $
@@ -40,7 +40,7 @@ toReport exit =
4040 ["In","JavaScript","folks","run","`npm install`","to","start","projects."
4141 ,"\"Gotta","download","everything!\"","But","why","download","packages"
4242 ,"again","and","again?","Instead,","Elm","caches","packages","in"
43− ,D.dullyellow (D.fromString cacheDir)
43+ ,D.dullyellow (D.fromString elmHome)
4444 ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
4545 ,"Elm","projects","check","that","cache","before","trying","the","internet."
4646 ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
ui/terminal/src/Install.hs+5−2
@@ -5,7 +5,10 @@ module Install
55 where
66
77
8+import Control.Monad.Trans (liftIO)
9+
810import qualified Elm.Install as Install
11+import qualified Elm.PerUserCache as PerUserCache
912import qualified Elm.Package as Pkg
1013import qualified Reporting.Exit as Exit
1114import qualified Reporting.Exit.Install as E
@@ -28,8 +31,8 @@ run args () =
2831 Task.run reporter $
2932 case args of
3033 NoArgs ->
31− do cacheDir <- Task.getPackageCacheDir
32− Task.throw (Exit.Install (E.NoArgs cacheDir))
34+ do elmHome <- liftIO PerUserCache.getElmHome
35+ Task.throw (Exit.Install (E.NoArgs elmHome))
3336
3437 Install pkg ->
3538 Install.install pkg