Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Expose the status of currently-running tasks #239

Merged
merged 32 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bd618da
Use concurrent-output package for sticky line
cnr Apr 7, 2021
4548fed
Add fused-effects wrapper for System.Console.Regions
cnr Apr 7, 2021
fc3d1df
Use concurrent-output for raw logger
cnr Apr 7, 2021
90e9f29
Try using a console region for sticky messages in Analyze
cnr Apr 7, 2021
0881de5
Add friendly interface for console sticky regions
cnr Apr 13, 2021
abffe21
Eliminate logSticky
cnr Apr 13, 2021
44671c1
Eliminate ResultBundle; eliminate SevTrace; prototype StickyDiag
cnr May 17, 2021
e31aca7
Remove logStdout from Logger effect; create new string conversion uti…
cnr May 17, 2021
bd6cc47
Improve formatting for log messages
cnr May 18, 2021
9ee5df3
Add new errorBoundary primitive to Diagnostics
cnr May 18, 2021
a5cd056
Flush logger output
cnr May 18, 2021
3e29fd2
Improve formatting of diagnostics errors
cnr May 18, 2021
284b7d4
Add Diagnostics context to each analyzer
cnr May 18, 2021
b05b360
Add Fresh effect; use it for sticky task IDs
cnr May 18, 2021
20ef890
Use logDebug for sticky fallback
cnr May 18, 2021
5f0489a
Always logDebug sticky messages
cnr May 18, 2021
f7841ee
Fix compile warnings
cnr May 18, 2021
7ec81e0
Introduce new StickyLogger effect
cnr May 23, 2021
31a8b6a
Add comment about behavior of `context`
cnr May 23, 2021
8ba9835
Add docs to FunctionalDependencies use site
cnr May 24, 2021
6c362b7
Don't use (&)
cnr May 24, 2021
52af79a
Add comment to WalkSkipAll change for gradle
cnr May 24, 2021
2765734
Un-qualify `Diag.context`
cnr May 24, 2021
f6bbaa8
Rename Fresh to AtomicCounter
cnr May 24, 2021
fe8827c
Collapse reader effects for StickyDiagC
cnr May 24, 2021
2fc7da2
Fix doc typo
cnr May 24, 2021
c97e8ef
s/primary/unique
cnr May 24, 2021
93370e7
minor doc fixup
cnr May 24, 2021
d91163c
Address review feedback
cnr May 24, 2021
f36d073
Merge remote-tracking branch 'origin/master' into task-status
cnr May 24, 2021
25450a4
Fix test compile error
cnr May 24, 2021
a808fe7
Inherit the parent context stack in errorBoundary
cnr May 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/Control/Effect/Diagnostics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ where

import Control.Algebra as X
import Control.Exception (SomeException (..))
import Data.List (intersperse)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (catMaybes)
import Data.Semigroup (sconcat)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Prettyprint.Doc
import Data.Text.Prettyprint.Doc.Render.Terminal (AnsiStyle)
import Data.Text.Prettyprint.Doc.Render.Terminal
import Prelude

data Diagnostics m k where
Expand Down Expand Up @@ -146,19 +147,26 @@ instance Show FailureBundle where
renderFailureBundle :: FailureBundle -> Doc AnsiStyle
renderFailureBundle FailureBundle {..} =
vsep
[ "----------",
"An error occurred:",
[ annotate (color Yellow) "----------",
annotate (color Yellow) "An error occurred:",
"",
indent 4 (align (renderSomeDiagnostic failureCause)),
indent 4 (renderSomeDiagnostic failureCause),
"",
">>>",
indent 2 "Relevant warnings include:",
"",
indent 4 (align (renderWarnings failureWarnings))
indent 2 (annotate (color Yellow) "Relevant warnings include:"),
"",
indent 4 (renderWarnings failureWarnings)
]

renderSomeDiagnostic :: SomeDiagnostic -> Doc AnsiStyle
renderSomeDiagnostic (SomeDiagnostic stack cause) = renderDiagnostic cause <> line <> align (indent 2 (vsep (map (pretty . ("when " <>)) stack)))
renderSomeDiagnostic (SomeDiagnostic stack cause) =
renderDiagnostic cause
<> line
<> line
<> annotate (color Cyan) "Traceback:"
<> line
<> indent 2 (vsep (map (pretty . ("- " <>)) stack))

renderWarnings :: [SomeDiagnostic] -> Doc AnsiStyle
renderWarnings = align . vsep . map renderSomeDiagnostic
renderWarnings = vsep . intersperse (line <> "--" <> line) . map renderSomeDiagnostic
19 changes: 16 additions & 3 deletions src/Effect/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Data.String (fromString)
import Data.String.Conversion (decodeUtf8)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Prettyprint.Doc (pretty, viaShow)
import Data.Text.Prettyprint.Doc (pretty, viaShow, vsep, line, indent)
import Data.Void (Void)
import GHC.Generics (Generic)
import Path
Expand Down Expand Up @@ -129,7 +129,20 @@ data ExecErr

instance ToDiagnostic ExecErr where
renderDiagnostic = \case
CommandFailed err -> "Command execution failed: " <> viaShow err
CommandFailed err ->
"Command execution failed: "
<> line
<> indent
4
( vsep
[ "command: " <> pretty (cmdFailureName err)
, "args: " <> pretty (cmdFailureArgs err)
, "dir: " <> pretty (cmdFailureDir err)
, "exit: " <> viaShow (cmdFailureExit err)
, "stdout: " <> line <> indent 2 (pretty @Text (decodeUtf8 (cmdFailureStdout err)))
, "stderr: " <> line <> indent 2 (pretty @Text (decodeUtf8 (cmdFailureStderr err)))
]
)
CommandParseError cmd err -> "Failed to parse command output. command: " <> viaShow cmd <> " . error: " <> pretty err

-- | Execute a command and return its @(exitcode, stdout, stderr)@
Expand All @@ -156,7 +169,7 @@ execJson dir cmd = do

-- | A variant of 'exec' that throws a 'ExecErr' when the command returns a non-zero exit code
execThrow :: (Has Exec sig m, Has Diagnostics sig m) => Path x Dir -> Command -> m BL.ByteString
execThrow dir cmd = context ("Running command: " <> T.pack (show cmd)) $ do
execThrow dir cmd = context ("Running command '" <> cmdName cmd <> "'") $ do
result <- exec dir cmd
case result of
Left failure -> fatal (CommandFailed failure)
Expand Down
2 changes: 1 addition & 1 deletion src/Effect/Logger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ termLoggerFormatter :: LogFormatter
termLoggerFormatter sev msg = renderIt $ formatCommon sev msg <> line

formatCommon :: Severity -> Doc AnsiStyle -> Doc AnsiStyle
formatCommon sev msg = pretty '[' <> showSev sev <> pretty @String "] " <> msg
formatCommon sev msg = hang 2 (pretty '[' <> showSev sev <> pretty @String "] " <> msg)
where
showSev SevError = annotate (color Red) (pretty @String "ERROR")
showSev SevWarn = annotate (color Yellow) (pretty @String " WARN")
Expand Down
19 changes: 14 additions & 5 deletions src/Effect/ReadFS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import Data.Kind (Type)
import Data.String.Conversion (decodeUtf8)
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Prettyprint.Doc (pretty)
import Data.Text.Prettyprint.Doc (pretty, line, indent, vsep)
import Data.Void (Void)
import Data.Yaml (decodeEither', prettyPrintParseException)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -100,10 +100,19 @@ $(deriveReplayable ''ReadFS)

instance ToDiagnostic ReadFSErr where
renderDiagnostic = \case
FileReadError path err -> "Error reading file " <> pretty path <> " : " <> pretty err
FileParseError path err -> "Error parsing file " <> pretty path <> " : " <> pretty err
ResolveError base rel err -> "Error resolving a relative file. base: " <> pretty base <> " . relative: " <> pretty rel <> " . error: " <> pretty err
ListDirError dir err -> "Error listing directory contents at " <> pretty dir <> " : " <> pretty err
FileReadError path err -> "Error reading file " <> pretty path <> ":" <> line <> indent 4 (pretty err)
FileParseError path err -> "Error parsing file " <> pretty path <> ":" <> line <> indent 4 (pretty err)
ResolveError base rel err ->
"Error resolving a relative file:" <> line
<> indent
4
( vsep
[ "base: " <> pretty base
, "relative: " <> pretty rel
, "error: " <> pretty err
]
)
ListDirError dir err -> "Error listing directory contents at " <> pretty dir <> ":" <> line <> indent 2 (pretty err)

-- | Read file contents into a strict 'ByteString'
readContentsBS' :: Has ReadFS sig m => Path b File -> m (Either ReadFSErr ByteString)
Expand Down
4 changes: 2 additions & 2 deletions src/Strategy/Gradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ findProjects = walk' $ \dir _ files -> do
Just _ -> do

projectsStdout <- errorBoundary .
context ("getting gradle projects rooted at " <> pathToText dir) $
context ("Listing gradle projects at " <> pathToText dir) $
execThrow dir (gradleProjectsCmd (pathToText dir <> "gradlew"))
<||> execThrow dir (gradleProjectsCmd (pathToText dir <> "gradlew.bat"))
<||> execThrow dir (gradleProjectsCmd "gradle")

case projectsStdout of
Left err -> do
logWarn $ renderFailureBundle err
pure ([], WalkContinue)
pure ([], WalkSkipAll)
skilly-lily marked this conversation as resolved.
Show resolved Hide resolved
Right result -> do
let subprojects = parseProjects result

Expand Down