on master help sign in
split Reporting.Exit.Publish into its own type
commit80f2c62363ad176df7b70dcf9e818997647d1ce9 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 4 Jun 2019, 15:43 (7 years ago) parent1007086
1 file changed+257−247
builder/src/Reporting/Exit.hs+257−247
builder/src/Reporting/Exit.hs+257−247
@@ -1,8 +1,6 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Reporting.Exit
3− ( Exit(..)
4− --
5− , Init(..)
3+ ( Init(..)
64 , initToReport
75 --
86 , Diff(..)
@@ -12,6 +10,9 @@ module Reporting.Exit
1210 , bumpToReport
1311 , newPackageOverview
1412 --
13+ , Publish(..)
14+ , publishToReport
15+ --
1516 , Install(..)
1617 , installToReport
1718 --
@@ -30,6 +31,7 @@ module Reporting.Exit
3031 , makeToReport
3132 --
3233 , DocsProblem(..)
34+ --
3335 , toString
3436 , toStderr
3537 , toJson
@@ -60,39 +62,6 @@ import qualified Reporting.Error as Error
6062
6163
6264
63−-- ALL POSSIBLE ERRORS
64−
65−
66−data Exit
67− -- publish
68− = PublishMustHaveLatestRegistry RegistryProblem
69− | PublishApplication
70− | PublishNotInitialVersion V.Version
71− | PublishAlreadyPublished V.Version
72− | PublishInvalidBump V.Version V.Version
73− | PublishBadBump V.Version V.Version M.Magnitude V.Version M.Magnitude
74− | PublishNoSummary
75− | PublishNoExposed
76− | PublishNoReadme
77− | PublishShortReadme
78− | PublishNoLicense
79− | PublishCannotGetTag Http.Error
80− | PublishCannotGetZip Http.Error
81− | PublishCannotDecodeZip
82− | PublishCannotGetDocs DocsProblem
83− | PublishCannotRegister Http.Error
84− | PublishMissingTag V.Version
85− | PublishNoGit
86− | PublishLocalChanges V.Version
87−
88−
89−data DocsProblem
90− = DP_Http Http.Error
91− | DP_Data
92− | DP_Cache
93−
94−
95−
9665-- INIT
9766
9867
@@ -286,218 +255,41 @@ newPackageOverview =
286255
287256
288257
289−-- INSTALL
290−
291−
292−data Install
293− = InstallNoProject
294− | InstallNoArgs FilePath
295− | InstallNoOnlineSolution
296− | InstallNoOfflineSolution
297− | InstallHadSolverTrouble Solver
298− | InstallUnknownPackageOnline [Pkg.Name]
299− | InstallUnknownPackageOffline [Pkg.Name]
300− | InstallHasBadDetails Details
301−
302−
303−installToReport :: Install -> Help.Report
304−installToReport exit =
305− case exit of
306− InstallNoProject ->
307− Help.report "NEW PROJECT?" Nothing
308− "Are you trying to start a new project? Try this command instead:"
309− [ D.indent 4 $ D.green "elm init"
310− , D.reflow "It will help you get started!"
311− ]
312−
313− InstallNoArgs elmHome ->
314− Help.report "INSTALL WHAT?" Nothing
315− "I am expecting commands like:"
316− [ D.green $ D.indent 4 $ D.vcat $
317− [ "elm install elm/http"
318− , "elm install elm/json"
319− , "elm install elm/random"
320− ]
321− , D.toFancyHint
322− ["In","JavaScript","folks","run","`npm install`","to","start","projects."
323− ,"\"Gotta","download","everything!\"","But","why","download","packages"
324− ,"again","and","again?","Instead,","Elm","caches","packages","in"
325− ,D.dullyellow (D.fromChars elmHome)
326− ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
327− ,"Elm","projects","check","that","cache","before","trying","the","internet."
328− ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
329− ,"easier","to","work","offline.","As","a","result"
330− ,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
331− ,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
332− ,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
333− ]
334− ]
335−
336− InstallNoOnlineSolution ->
337− Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json") -- TODO recommend using solver in `elm reactor`
338− "This usually happens if you try to modify dependency constraints by\
339− \ hand. I recommend deleting any dependency you added recently (or all\
340− \ of them if things are bad) and then adding them again with:"
341− [ D.indent 4 $ D.green "elm install"
342− , D.reflow $
343− "And do not be afaid to ask for help on Slack if you get stuck!"
344− ]
345−
346− InstallNoOfflineSolution ->
347− error "TODO InstallNoOfflineSolution"
348−
349− InstallHadSolverTrouble solver ->
350− error "TODO InstallHadSolverTrouble" solver
351−
352− InstallUnknownPackageOnline suggestions ->
353− error "TODO InstallUnknownPackageOnline" suggestions
354−
355− InstallUnknownPackageOffline suggestions ->
356− error "TODO InstallUnknownPackageOffline" suggestions
357−
358− InstallHasBadDetails _ ->
359− error "TODO InstallHasBadDetails"
360−
361−
362−{- TODO detect if library has no 0.19.0 version. Maybe do this on website though?
363− Help.report "OLD DEPENDENCIES" (Just "elm.json")
364− ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
365− )
366− [ D.indent 4 $ D.vcat $ map (D.red . D.fromUtf8 . Pkg.toString) badPackages
367− , D.reflow $
368− "This may be because it is not upgraded yet. It may be because a\
369− \ better solution came along, so there was no need to upgrade it.\
370− \ Etc. Try asking around on Slack to learn more about the topic."
371− , D.toSimpleNote
372− "Whatever the case, please be kind to the relevant package authors! Having\
373− \ friendly interactions with users is great motivation, and conversely, getting\
374− \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
375− \ authors are humans with families, friends, jobs, vacations, responsibilities,\
376− \ goals, etc. They face obstacles outside of their technical work you will never\
377− \ know about, so please assume the best and try to be patient and supportive!"
378− ]
379−-}
380−
381−
382−
383−-- SOLVER
384−
385−
386−data Solver
387− = SolverBadCacheData Pkg.Name V.Version
388− | SolverBadHttpData Pkg.Name V.Version
389− | SolverBadHttp Http.Error
390−
391−
392−
393−-- OUTLINE
394−
395−
396−data Outline
397− = OutlineHasBadStructure (Decode.Error OutlineProblem)
398− | OutlineHasBadSrcDirs FilePath [FilePath]
399−
400−
401−data OutlineProblem
402− = OP_BadType
403− | OP_BadPkgName Row Col
404− | OP_BadVersion Row Col
405− | OP_BadConstraint C.Error
406− | OP_BadModuleName Row Col
407− | OP_BadModuleHeaderTooLong
408− | OP_BadDependencyName Row Col
409− | OP_BadLicense Json.String [Json.String]
410− | OP_BadSummaryTooLong
411− | OP_NoSrcDirs
412−
413−
414−
415−-- DETAILS
416−
417−
418−data Details
419− = DetailsCorrupt
420− | DetailsNoSolution
421− | DetailsNoOfflineSolution
422− | DetailsSolverProblem Solver
423− | DetailsBadElmInPkg C.Constraint
424− | DetailsBadElmInAppOutline V.Version
425− | DetailsHandEditedDependencies
426− | DetailsBadOutline Outline
427− | DetailsCannotGetRegistry RegistryProblem
428− | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
429−
430−
431−data RegistryProblem
432− = RP_Http Http.Error
433− | RP_Data
434−
435−
436−data PackageProblem
437− = PP_BadEndpointRequest Http.Error
438− | PP_BadEndpointContent
439− | PP_BadArchiveRequest Http.Error
440− | PP_BadArchiveContent
441− | PP_BadArchiveHash String String
442−
443−
444−
445−-- MAKE
446−
447−
448−data Make
449− = MakeNeedsOutline
450− | MakeCannotOptimizeAndDebug
451− | MakeBlockedByDetailsProblem Details
452− | MakeAppNeedsFileNames
453− | MakePkgNeedsExposing
454− | MakeMultipleFilesIntoHtml
455− | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
456− | MakeCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
457− | MakeCannotBuild BuildProblem
458− | MakeCannotLoadArtifacts
459−
460−
461−data BuildProblem
462− = BuildModuleProblems Error.Module [Error.Module]
463− | BuildProjectProblem BuildProjectProblem
258+-- PUBLISH
464259
465260
466−data BuildProjectProblem
467− = BP_PathUnknown FilePath
468− | BP_WithBadExtension FilePath
469− | BP_WithAmbiguousSrcDir FilePath FilePath
470− | BP_MainPathDuplicate FilePath FilePath
471− | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
472− | BP_CannotLoadDependencies
473− | BP_Cycle ModuleName.Raw [ModuleName.Raw]
474− | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
475−
476−
477−
478−-- RENDERERS
479−
480−
481−toString :: Help.Report -> String
482−toString report =
483− Help.toString (Help.reportToDoc report)
484−
485−
486−toStderr :: Help.Report -> IO ()
487−toStderr report =
488− Help.toStderr (Help.reportToDoc report)
489−
490−
491−toJson :: Help.Report -> Encode.Value
492−toJson report =
493− Help.reportToJson report
261+data Publish
262+ = PublishNoOutline
263+ | PublishBadOutline Outline
264+ | PublishMustHaveLatestRegistry RegistryProblem
265+ | PublishApplication
266+ | PublishNotInitialVersion V.Version
267+ | PublishAlreadyPublished V.Version
268+ | PublishInvalidBump V.Version V.Version
269+ | PublishBadBump V.Version V.Version M.Magnitude V.Version M.Magnitude
270+ | PublishNoSummary
271+ | PublishNoExposed
272+ | PublishNoReadme
273+ | PublishShortReadme
274+ | PublishNoLicense
275+ | PublishCannotGetTag Http.Error
276+ | PublishCannotGetZip Http.Error
277+ | PublishCannotDecodeZip
278+ | PublishCannotGetDocs DocsProblem
279+ | PublishCannotRegister Http.Error
280+ | PublishMissingTag V.Version
281+ | PublishNoGit
282+ | PublishLocalChanges V.Version
494283
495284
496−_toReport :: Exit -> Help.Report
497−_toReport exit =
498− case exit of
285+publishToReport :: Publish -> Help.Report
286+publishToReport publish =
287+ case publish of
288+ PublishNoOutline ->
289+ error "TODO PublishNoOutline"
499290
500− -- publish
291+ PublishBadOutline problem ->
292+ error "TODO PublishBadOutline" problem
501293
502294 PublishMustHaveLatestRegistry problem ->
503295 error "TODO PublishMustHaveLatestRegistry" problem
@@ -609,12 +401,12 @@ _toReport exit =
609401 ]
610402
611403 PublishNoReadme ->
612− badReadmeReport "NO README" $
404+ toBadReadmeReport "NO README" $
613405 "Every published package must have a helpful README.md\
614406 \ file, but I do not see one in your project."
615407
616408 PublishShortReadme ->
617− badReadmeReport "SHORT README" $
409+ toBadReadmeReport "SHORT README" $
618410 "This README.md is too short. Having more details will help\
619411 \ people assess your package quickly and fairly."
620412
@@ -695,8 +487,8 @@ _toReport exit =
695487 ]
696488
697489
698−badReadmeReport :: String -> String -> Help.Report
699−badReadmeReport title summary =
490+toBadReadmeReport :: String -> String -> Help.Report
491+toBadReadmeReport title summary =
700492 Help.report title (Just "README.md") summary
701493 [ D.reflow $
702494 "When people look at your README, they are wondering:"
@@ -719,6 +511,224 @@ badReadmeReport title summary =
719511
720512
721513
514+-- DOCS
515+
516+
517+data DocsProblem
518+ = DP_Http Http.Error
519+ | DP_Data
520+ | DP_Cache
521+
522+
523+
524+-- INSTALL
525+
526+
527+data Install
528+ = InstallNoProject
529+ | InstallNoArgs FilePath
530+ | InstallNoOnlineSolution
531+ | InstallNoOfflineSolution
532+ | InstallHadSolverTrouble Solver
533+ | InstallUnknownPackageOnline [Pkg.Name]
534+ | InstallUnknownPackageOffline [Pkg.Name]
535+ | InstallHasBadDetails Details
536+
537+
538+installToReport :: Install -> Help.Report
539+installToReport exit =
540+ case exit of
541+ InstallNoProject ->
542+ Help.report "NEW PROJECT?" Nothing
543+ "Are you trying to start a new project? Try this command instead:"
544+ [ D.indent 4 $ D.green "elm init"
545+ , D.reflow "It will help you get started!"
546+ ]
547+
548+ InstallNoArgs elmHome ->
549+ Help.report "INSTALL WHAT?" Nothing
550+ "I am expecting commands like:"
551+ [ D.green $ D.indent 4 $ D.vcat $
552+ [ "elm install elm/http"
553+ , "elm install elm/json"
554+ , "elm install elm/random"
555+ ]
556+ , D.toFancyHint
557+ ["In","JavaScript","folks","run","`npm install`","to","start","projects."
558+ ,"\"Gotta","download","everything!\"","But","why","download","packages"
559+ ,"again","and","again?","Instead,","Elm","caches","packages","in"
560+ ,D.dullyellow (D.fromChars elmHome)
561+ ,"so","each","one","is","downloaded","and","built","ONCE","on","your","machine."
562+ ,"Elm","projects","check","that","cache","before","trying","the","internet."
563+ ,"This","reduces","build","times,","reduces","server","costs,","and","makes","it"
564+ ,"easier","to","work","offline.","As","a","result"
565+ ,D.dullcyan "elm install","is","only","for","adding","dependencies","to","elm.json,"
566+ ,"whereas",D.dullcyan "elm make","is","in","charge","of","gathering","dependencies"
567+ ,"and","building","everything.","So","maybe","try",D.green "elm make","instead?"
568+ ]
569+ ]
570+
571+ InstallNoOnlineSolution ->
572+ Help.report "UNSOLVABLE DEPENDENCIES" (Just "elm.json") -- TODO recommend using solver in `elm reactor`
573+ "This usually happens if you try to modify dependency constraints by\
574+ \ hand. I recommend deleting any dependency you added recently (or all\
575+ \ of them if things are bad) and then adding them again with:"
576+ [ D.indent 4 $ D.green "elm install"
577+ , D.reflow $
578+ "And do not be afaid to ask for help on Slack if you get stuck!"
579+ ]
580+
581+ InstallNoOfflineSolution ->
582+ error "TODO InstallNoOfflineSolution"
583+
584+ InstallHadSolverTrouble solver ->
585+ error "TODO InstallHadSolverTrouble" solver
586+
587+ InstallUnknownPackageOnline suggestions ->
588+ error "TODO InstallUnknownPackageOnline" suggestions
589+
590+ InstallUnknownPackageOffline suggestions ->
591+ error "TODO InstallUnknownPackageOffline" suggestions
592+
593+ InstallHasBadDetails _ ->
594+ error "TODO InstallHasBadDetails"
595+
596+
597+{- TODO detect if library has no 0.19.0 version. Maybe do this on website though?
598+ Help.report "OLD DEPENDENCIES" (Just "elm.json")
599+ ( "The following packages do not work with Elm " ++ V.toChars V.compiler ++ " right now:"
600+ )
601+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromUtf8 . Pkg.toString) badPackages
602+ , D.reflow $
603+ "This may be because it is not upgraded yet. It may be because a\
604+ \ better solution came along, so there was no need to upgrade it.\
605+ \ Etc. Try asking around on Slack to learn more about the topic."
606+ , D.toSimpleNote
607+ "Whatever the case, please be kind to the relevant package authors! Having\
608+ \ friendly interactions with users is great motivation, and conversely, getting\
609+ \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
610+ \ authors are humans with families, friends, jobs, vacations, responsibilities,\
611+ \ goals, etc. They face obstacles outside of their technical work you will never\
612+ \ know about, so please assume the best and try to be patient and supportive!"
613+ ]
614+-}
615+
616+
617+
618+-- SOLVER
619+
620+
621+data Solver
622+ = SolverBadCacheData Pkg.Name V.Version
623+ | SolverBadHttpData Pkg.Name V.Version
624+ | SolverBadHttp Http.Error
625+
626+
627+
628+-- OUTLINE
629+
630+
631+data Outline
632+ = OutlineHasBadStructure (Decode.Error OutlineProblem)
633+ | OutlineHasBadSrcDirs FilePath [FilePath]
634+
635+
636+data OutlineProblem
637+ = OP_BadType
638+ | OP_BadPkgName Row Col
639+ | OP_BadVersion Row Col
640+ | OP_BadConstraint C.Error
641+ | OP_BadModuleName Row Col
642+ | OP_BadModuleHeaderTooLong
643+ | OP_BadDependencyName Row Col
644+ | OP_BadLicense Json.String [Json.String]
645+ | OP_BadSummaryTooLong
646+ | OP_NoSrcDirs
647+
648+
649+
650+-- DETAILS
651+
652+
653+data Details
654+ = DetailsCorrupt
655+ | DetailsNoSolution
656+ | DetailsNoOfflineSolution
657+ | DetailsSolverProblem Solver
658+ | DetailsBadElmInPkg C.Constraint
659+ | DetailsBadElmInAppOutline V.Version
660+ | DetailsHandEditedDependencies
661+ | DetailsBadOutline Outline
662+ | DetailsCannotGetRegistry RegistryProblem
663+ | DetailsCannotBuildPackage Pkg.Name V.Version PackageProblem
664+
665+
666+data RegistryProblem
667+ = RP_Http Http.Error
668+ | RP_Data
669+
670+
671+data PackageProblem
672+ = PP_BadEndpointRequest Http.Error
673+ | PP_BadEndpointContent
674+ | PP_BadArchiveRequest Http.Error
675+ | PP_BadArchiveContent
676+ | PP_BadArchiveHash String String
677+
678+
679+
680+-- MAKE
681+
682+
683+data Make
684+ = MakeNeedsOutline
685+ | MakeCannotOptimizeAndDebug
686+ | MakeBlockedByDetailsProblem Details
687+ | MakeAppNeedsFileNames
688+ | MakePkgNeedsExposing
689+ | MakeMultipleFilesIntoHtml
690+ | MakeNonMainFilesIntoJavaScript ModuleName.Raw [ModuleName.Raw]
691+ | MakeCannotOptimizeDebugValues ModuleName.Raw [ModuleName.Raw]
692+ | MakeCannotBuild BuildProblem
693+ | MakeCannotLoadArtifacts
694+
695+
696+data BuildProblem
697+ = BuildModuleProblems Error.Module [Error.Module]
698+ | BuildProjectProblem BuildProjectProblem
699+
700+
701+data BuildProjectProblem
702+ = BP_PathUnknown FilePath
703+ | BP_WithBadExtension FilePath
704+ | BP_WithAmbiguousSrcDir FilePath FilePath
705+ | BP_MainPathDuplicate FilePath FilePath
706+ | BP_MainNameDuplicate ModuleName.Raw FilePath FilePath
707+ | BP_CannotLoadDependencies
708+ | BP_Cycle ModuleName.Raw [ModuleName.Raw]
709+ | BP_MissingExposed (NE.List (ModuleName.Raw, Import.Problem))
710+
711+
712+
713+-- RENDERERS
714+
715+
716+toString :: Help.Report -> String
717+toString report =
718+ Help.toString (Help.reportToDoc report)
719+
720+
721+toStderr :: Help.Report -> IO ()
722+toStderr report =
723+ Help.toStderr (Help.reportToDoc report)
724+
725+
726+toJson :: Help.Report -> Encode.Value
727+toJson report =
728+ Help.reportToJson report
729+
730+
731+
722732-- DETAILS TO REPORT
723733
724734