@@ -2,11 +2,13 @@ module Terminal.Run exposing
22 ( Error
33 , make
44 , run
5+ , prettifyError
56 )
67
78{-| Support the `gren run ModuleName` command.
89-}
910
11+ import CLI.PrettyPrinter as PP
1012import Compiler.PackageName as PackageName exposing (PackageName)
1113import Compiler.Backend as Backend
1214import Bytes exposing (Bytes)
@@ -24,17 +26,13 @@ import Process
2426import Stream
2527import Task exposing (Task)
2628import Terminal.PackageInstall as PackageInstall exposing (PackageResolution)
29+ import Terminal.Help as Help
2730
2831
2932type Error
3033 = TempPathError FileSystem.Error
3134 | ReadProjectOutlineError PackageInstall.ReadProjectOutlineError
32- | ReadOutlineError FileSystem.Error
33- | InvalidProjectOutline Decode.Error
3435 | PackageInstallError PackageInstall.PackageInstallError
35- | PackageFetchError Git.Error
36- | GitError Git.Error
37- | NoPackageVersions
3836 | NotAnApplication
3937
4038
@@ -156,17 +154,27 @@ clonePackage config packageName =
156154 FileSystem.makeTempDirectory config.fsPermission "gren-run"
157155 |> Task.mapError TempPathError
158156
159- getVersion =
157+ clone tempDir =
160158 Git.fetchLatestVersion config.cpPermission packageName
161- |> Task.mapError GitError
162-
163- clone tempDir version =
164- Git.clonePackage config.cpPermission tempDir packageName version
165- |> Task.mapError PackageFetchError
159+ |> Task.andThen
160+ (\version ->
161+ Git.clonePackage
162+ config.cpPermission
163+ tempDir
164+ packageName
165+ version
166+ )
167+ |> Task.mapError
168+ (\e ->
169+ PackageInstallError <|
170+ PackageInstall.PackageInstallGitError <|
171+ { package = packageName
172+ , error = e
173+ }
174+ )
166175 in
167176 Task.await getTempDir <| \tempDir ->
168- Task.await getVersion <| \version ->
169- Task.await (clone tempDir version) <| \_ ->
177+ Task.await (clone tempDir) <| \_ ->
170178 Task.await (getProjectOutline config.fsPermission tempDir) <| \outline ->
171179 Task.succeed
172180 { projectPath = tempDir
@@ -230,15 +238,16 @@ getProjectOutline fsPermission path =
230238 path
231239 |> Path.append (Path.fromPosixString "gren.json")
232240 |> PackageInstall.readOutline fsPermission
233- |> Task.mapError ReadOutlineError
241+ |> Task.mapError (PackageInstall.ReadProjectOutlineNoProject >> ReadProjectOutlineError)
234242 |> Task.andThen
235243 (\decodeResult ->
236244 when decodeResult is
237245 Ok outline ->
238246 Task.succeed outline
239247 Err err ->
240248 err
241- |> InvalidProjectOutline
249+ |> PackageInstall.ReadProjectOutlineInvalidGrenJson
250+ |> ReadProjectOutlineError
242251 |> Task.fail
243252 )
244253
@@ -268,3 +277,37 @@ getOutputPath projectOutline =
268277 Just (getPath Backend.Html "app.html")
269278 Platform.Common ->
270279 Nothing
280+
281+
282+ prettifyError : Error -> PP.Document
283+ prettifyError error =
284+ when error is
285+ TempPathError err ->
286+ Help.report
287+ "FILESYSTEM ERROR"
288+ Nothing
289+ (PP.verticalBlock
290+ [ PP.words "Failed to access temporary file path."
291+ , PP.empty
292+ , PP.words "The error provided by the operating system is:"
293+ , PP.empty
294+ , PP.words (FileSystem.errorToString err)
295+ |> PP.color PP.Red
296+ |> PP.indent
297+ ]
298+ )
299+
300+ NotAnApplication ->
301+ Help.report
302+ "NOT AN APPLICATION"
303+ Nothing
304+ ( PP.words
305+ "The module you are trying to run is not an application."
306+ )
307+
308+ ReadProjectOutlineError err ->
309+ PackageInstall.prettifyProjectOutlineError err
310+
311+ PackageInstallError err ->
312+ PackageInstall.prettifyError err
313+
0 commit comments