Skip to content

Commit 59e6c1e

Browse files
committed
Seperate type for errors related to reading the project outline.
1 parent 955edf4 commit 59e6c1e

File tree

3 files changed

+57
-36
lines changed

3 files changed

+57
-36
lines changed

src/Main.gren

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -448,29 +448,35 @@ parseUserArgs model compilerPath =
448448
, stdin = model.stdin
449449
}
450450
projectOutline
451-
)
452-
|> Task.map
453-
(\resolved ->
454-
Compiler.Backend.run
455-
model.cpPermission
456-
{ useColor = model.useColor
457-
, compilerPath = compilerPath
458-
, pathToString = model.pathToString
459-
, connection = initWithCommand <|
460-
Compiler.Backend.Make
461-
{ optimize = flags.optimize
462-
, sourcemaps = flags.sourcemaps
463-
, output = flags.output
464-
, report = flags.report
465-
, projectPath = resolved.projectPath
466-
, entryPoints = flags.entryPoints
467-
, outline = resolved.outline
468-
, rootSources = resolved.rootSources
469-
, dependencies = resolved.dependencies
470-
}
471-
, onComplete = CompilerRan
472-
}
473-
)
451+
|> Task.map
452+
(\resolved ->
453+
Compiler.Backend.run
454+
model.cpPermission
455+
{ useColor = model.useColor
456+
, compilerPath = compilerPath
457+
, pathToString = model.pathToString
458+
, connection = initWithCommand <|
459+
Compiler.Backend.Make
460+
{ optimize = flags.optimize
461+
, sourcemaps = flags.sourcemaps
462+
, output = flags.output
463+
, report = flags.report
464+
, projectPath = resolved.projectPath
465+
, entryPoints = flags.entryPoints
466+
, outline = resolved.outline
467+
, rootSources = resolved.rootSources
468+
, dependencies = resolved.dependencies
469+
}
470+
, onComplete = CompilerRan
471+
}
472+
)
473+
|> Task.onError
474+
(\err ->
475+
Stream.Log.line model.stdout (Debug.toString err)
476+
|> Task.execute
477+
|> Task.succeed
478+
)
479+
)
474480
|> Task.onError
475481
(\err ->
476482
Stream.Log.line model.stdout (Debug.toString err)
@@ -569,10 +575,14 @@ parseUserArgs model compilerPath =
569575
, stdin = model.stdin
570576
}
571577
projectOutline
572-
)
573-
|> Task.andThen
574-
(\err ->
575-
Stream.Log.line model.stdout "Done"
578+
|> Task.andThen
579+
(\err ->
580+
Stream.Log.line model.stdout "Done"
581+
)
582+
|> Task.onError
583+
(\err ->
584+
Stream.Log.line model.stdout (Debug.toString err)
585+
)
576586
)
577587
|> Task.onError
578588
(\err ->
@@ -594,6 +604,10 @@ parseUserArgs model compilerPath =
594604
}
595605
projectOutline
596606
requestedPackage
607+
|> Task.onError
608+
(\err ->
609+
Stream.Log.line model.stdout (Debug.toString err)
610+
)
597611
)
598612
|> Task.andThen
599613
(\err ->

src/Terminal/PackageInstall.gren

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ module Terminal.PackageInstall exposing
33
, PackageResolution
44
, run
55
, addPackage
6+
--
7+
, ReadProjectOutlineError (..)
68
, readProjectOutline
79
, readOutline
810
, localRepoPath
@@ -56,10 +58,7 @@ type alias PackageResolution =
5658

5759

5860
type PackageInstallError
59-
= PackageInstallNoProject FileSystem.Error
60-
| PackageInstallNoGrenJson FileSystem.Error
61-
| PackageInstallInvalidGrenJson Decode.Error
62-
| PackageInstallDebug String
61+
= PackageInstallDebug String
6362

6463

6564
run : Config -> Options -> Task PackageInstallError PackageResolution
@@ -501,6 +500,7 @@ addPackage config { projectPath, outline } requestedPackage =
501500
Task.fail <| PackageInstallDebug "Already installed"
502501

503502
else
503+
-- TODO: Implement
504504
Stream.Log.line config.stdout ("Installing " ++ packageNameStr)
505505

506506

@@ -537,14 +537,20 @@ localRepoPath name version projectPath =
537537
]
538538

539539

540-
readProjectOutline : FileSystem.Permission -> Task PackageInstallError { projectPath : Path, outline : Outline }
540+
type ReadProjectOutlineError
541+
= ReadProjectOutlineNoProject FileSystem.Error
542+
| ReadProjectOutlineNoGrenJson FileSystem.Error
543+
| ReadProjectOutlineInvalidGrenJson Decode.Error
544+
545+
546+
readProjectOutline : FileSystem.Permission -> Task ReadProjectOutlineError { projectPath : Path, outline : Outline }
541547
readProjectOutline fsPermission =
542548
Compiler.Paths.projectRoot fsPermission
543-
|> Task.mapError PackageInstallNoProject
549+
|> Task.mapError ReadProjectOutlineNoProject
544550
|> Task.andThen
545551
(\projectPath ->
546552
readOutline fsPermission (Path.append (Path.fromPosixString "gren.json") projectPath)
547-
|> Task.mapError PackageInstallNoGrenJson
553+
|> Task.mapError ReadProjectOutlineNoGrenJson
548554
|> Task.andThen
549555
(\decodeResult ->
550556
when decodeResult is
@@ -555,7 +561,7 @@ readProjectOutline fsPermission =
555561
}
556562

557563
Err err ->
558-
Task.fail (PackageInstallInvalidGrenJson err)
564+
Task.fail (ReadProjectOutlineInvalidGrenJson err)
559565
)
560566
)
561567

src/Terminal/Run.gren

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Terminal.PackageInstall as PackageInstall
2525

2626
type Error
2727
= TempPathError FileSystem.Error
28+
| ReadProjectOutlineError PackageInstall.ReadProjectOutlineError
2829
| PackageInstallError PackageInstall.PackageInstallError
2930
| NotAnApplication
3031

@@ -158,7 +159,7 @@ getNullStream =
158159
getProjectOutline : FileSystem.Permission -> Task Error { projectPath : Path, outline : Outline }
159160
getProjectOutline fsPermission =
160161
PackageInstall.readProjectOutline fsPermission
161-
|> Task.mapError PackageInstallError
162+
|> Task.mapError ReadProjectOutlineError
162163

163164

164165
getOutputPath : FileSystem.Permission -> Outline -> Task Error { outputType : (String -> Backend.MakeOutput), outputPath : Path }

0 commit comments

Comments
 (0)