Skip to content

Commit 5c6aa51

Browse files
committed
Prettify package validate errors.
1 parent 068dd46 commit 5c6aa51

File tree

3 files changed

+191
-145
lines changed

3 files changed

+191
-145
lines changed

builder/src/Reporting/Exit.hs

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ module Reporting.Exit
1313
replToReport,
1414
Validate (..),
1515
validateToReport,
16-
Uninstall (..),
17-
uninstallToReport,
18-
Outdated (..),
19-
outdatedToReport,
20-
Format (..),
21-
FormattingFailure (..),
22-
ValidateFailure (..),
23-
formatToReport,
2416
newPackageOverview,
2517
--
2618
Solver (..),
@@ -44,7 +36,6 @@ import Data.ByteString qualified as BS
4436
import Data.ByteString.UTF8 qualified as BS_UTF8
4537
import Data.List qualified as List
4638
import Data.Map qualified as Map
47-
import Data.Maybe (mapMaybe)
4839
import Data.Name qualified as N
4940
import Data.NonEmptyList qualified as NE
5041
import File qualified
@@ -63,7 +54,6 @@ import Reporting.Doc qualified as D
6354
import Reporting.Error qualified as Error
6455
import Reporting.Error.Import qualified as Import
6556
import Reporting.Error.Json qualified as Json
66-
import Reporting.Error.Syntax qualified as Error.Syntax
6757
import Reporting.Exit.Help qualified as Help
6858
import Reporting.Render.Code qualified as Code
6959
import System.FilePath ((<.>), (</>))
@@ -830,63 +820,6 @@ toDocsProblemReport problem context =
830820
\ for some reason."
831821
]
832822

833-
-- UNINSTALL
834-
835-
data Uninstall
836-
= UninstallNoOutline
837-
| UninstallBadOutline Outline
838-
| UninstallHadSolverTrouble Solver
839-
| UninstallNoSolverSolution
840-
| UninstallBadDetails Details
841-
842-
uninstallToReport :: Uninstall -> Help.Report
843-
uninstallToReport exit =
844-
case exit of
845-
UninstallNoOutline ->
846-
Help.report
847-
"COULD NOT FIND PROJECT"
848-
Nothing
849-
"I could not locate the gren.json file of your project."
850-
[]
851-
UninstallBadOutline outline ->
852-
toOutlineReport outline
853-
UninstallHadSolverTrouble solver ->
854-
toSolverReport solver
855-
UninstallNoSolverSolution ->
856-
Help.report
857-
"COULD NOT RESOLVE DEPENDENCIES"
858-
(Just "gren.json")
859-
( "After removing the package I was unable to resolve your project's dependencies.\
860-
\ I'm not sure how this can happen. It might be a good idea to reach out to the Gren\
861-
\ core team."
862-
)
863-
[]
864-
UninstallBadDetails details ->
865-
toDetailsReport details
866-
867-
-- OUTDATED
868-
869-
data Outdated
870-
= OutdatedNoOutline
871-
| OutdatedBadOutline Outline
872-
| OutdatedGitTrouble ()
873-
874-
outdatedToReport :: Outdated -> Help.Report
875-
outdatedToReport exit =
876-
case exit of
877-
OutdatedNoOutline ->
878-
Help.report
879-
"COULD NOT FIND PROJECT"
880-
Nothing
881-
"I could not locate the gren.json file of your project."
882-
[]
883-
OutdatedBadOutline outline ->
884-
toOutlineReport outline
885-
OutdatedGitTrouble gitError ->
886-
toGitErrorReport
887-
"PROBLEM FINDING OUTDATED PACKAGE VERSIONS"
888-
gitError
889-
"I tried to find newer versions of the dependencies specified in your gren.json file."
890823

891824
-- SOLVER
892825

@@ -2516,78 +2449,3 @@ replToReport problem =
25162449
corruptCacheReport
25172450
ReplBlocked ->
25182451
corruptCacheReport
2519-
2520-
-- FORMAT
2521-
2522-
data Format
2523-
= FormatPathUnknown FilePath
2524-
| FormatStdinWithFiles
2525-
| FormatNoOutline
2526-
| FormatBadOutline Outline
2527-
| FormatValidateErrors (NE.List ValidateFailure)
2528-
| FormatErrors (NE.List FormattingFailure)
2529-
2530-
data FormattingFailure
2531-
= FormattingFailureParseError (Maybe FilePath) BS.ByteString Error.Syntax.Error
2532-
2533-
data ValidateFailure
2534-
= VaildateFormattingFailure FormattingFailure
2535-
| ValidateNotCorrectlyFormatted
2536-
2537-
formatToReport :: Format -> Help.Report
2538-
formatToReport problem =
2539-
case problem of
2540-
FormatPathUnknown path ->
2541-
Help.report
2542-
"FILE NOT FOUND"
2543-
Nothing
2544-
"I cannot find this file:"
2545-
[ D.indent 4 $ D.red $ D.fromChars path,
2546-
D.reflow $ "Is there a typo?",
2547-
D.toSimpleNote $
2548-
"If you are just getting started, try working through the examples in the\
2549-
\ official guide https://gren-lang.org/learn to get an idea of the kinds of things\
2550-
\ that typically go in a src/Main.gren file."
2551-
]
2552-
FormatStdinWithFiles ->
2553-
Help.report
2554-
"INCOMPATIBLE FLAGS"
2555-
Nothing
2556-
"Files and stdin cannot be formatted at the same time."
2557-
[ D.reflow "You'll need to run `gren format` two separate times if you want to do both."
2558-
]
2559-
FormatNoOutline ->
2560-
Help.report
2561-
"FORMAT WHAT?"
2562-
Nothing
2563-
"I cannot find a gren.json so I am not sure what you want me to format.\
2564-
\ Normally you run `gren format` from within a project!"
2565-
[ D.reflow $ "If you need to format gren files outside of a project, tell me which files or directories to format:",
2566-
D.indent 4 $ D.green $ "gren format Example.gren"
2567-
]
2568-
FormatBadOutline outline ->
2569-
toOutlineReport outline
2570-
FormatValidateErrors errors ->
2571-
Help.report
2572-
"FILES NOT PROPERLY FORMATTED"
2573-
Nothing
2574-
"The input files were not correctly formatted according to Gren's preferred style."
2575-
(mapMaybe validateErrorToDoc $ NE.toList errors)
2576-
FormatErrors errors ->
2577-
Help.report
2578-
(show (length errors) <> " FILES CONTAINED ERRORS")
2579-
Nothing
2580-
"Some files contained errors and could not be formatted:"
2581-
(formattingErrorToDoc <$> NE.toList errors)
2582-
2583-
formattingErrorToDoc :: FormattingFailure -> D.Doc
2584-
formattingErrorToDoc formattingError =
2585-
case formattingError of
2586-
FormattingFailureParseError path source err ->
2587-
Help.syntaxErrorToDoc (Code.toSource source) path err
2588-
2589-
validateErrorToDoc :: ValidateFailure -> Maybe D.Doc
2590-
validateErrorToDoc validateError =
2591-
case validateError of
2592-
VaildateFormattingFailure formattingFailure -> Just $ formattingErrorToDoc formattingFailure
2593-
ValidateNotCorrectlyFormatted -> Nothing

src/Main.gren

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ parseUserArgs model compilerPath =
602602

603603
CliParser.PackageValidate ->
604604
Terminal.PackageInstall.readProjectOutline model.fsPermission
605-
|> Task.mapError Debug.toString
605+
|> Task.mapError Terminal.PackageInstall.prettifyProjectOutlineError
606606
|> Task.andThen
607607
(\projectOutline ->
608608
Terminal.PackageValidate.run
@@ -614,7 +614,7 @@ parseUserArgs model compilerPath =
614614
, stdin = model.stdin
615615
}
616616
projectOutline
617-
|> Task.mapError Debug.toString
617+
|> Task.mapError Terminal.PackageValidate.prettifyError
618618
)
619619
|> Task.map
620620
(\backendFlags ->
@@ -631,7 +631,8 @@ parseUserArgs model compilerPath =
631631
)
632632
|> Task.onError
633633
(\err ->
634-
Stream.Log.line model.stdout err
634+
Terminal.Help.prettyPrint printOpts err
635+
|> Stream.Log.string model.stderr
635636
|> Task.execute
636637
|> Task.succeed
637638
)

0 commit comments

Comments
 (0)