From 769c6f21690b6c6abb156b95b1a515cdd86f693c Mon Sep 17 00:00:00 2001 From: Jessica Black Date: Tue, 10 Sep 2024 16:43:16 -0700 Subject: [PATCH] Convert MSB errors to warnings --- src/App/Fossa/VSI/IAT/Resolve.hs | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/App/Fossa/VSI/IAT/Resolve.hs b/src/App/Fossa/VSI/IAT/Resolve.hs index b42db49258..d4ca289454 100644 --- a/src/App/Fossa/VSI/IAT/Resolve.hs +++ b/src/App/Fossa/VSI/IAT/Resolve.hs @@ -13,12 +13,13 @@ import App.Fossa.VSI.IAT.Types ( import App.Fossa.VSI.IAT.Types qualified as IAT import App.Fossa.VSI.Types qualified as VSI import Control.Algebra (Has) -import Control.Effect.Diagnostics (Diagnostics, context, fatalText, recover) +import Control.Effect.Diagnostics (Diagnostics, context, recover, warn) import Control.Effect.FossaApiClient (FossaApiClient, resolveProjectDependencies, resolveUserDefinedBinary) -import Data.Maybe (fromMaybe, isNothing) +import Control.Monad (unless) +import Data.Either (partitionEithers) import Data.String.Conversion (toText) import Data.Text (Text, intercalate) -import Graphing (Graphing, direct, edges, empty) +import Graphing (Graphing, direct, edges) import Srclib.Types ( SourceUserDefDep (..), ) @@ -48,30 +49,29 @@ resolveGraph locators skipResolving = context ("Resolving graph for " <> toText -- This typically means that the user doesn't have access to the project, or the project doesn't exist. -- Collect failed locators and report them to the user, along with mitigation suggestions. subgraphs <- traverseZipM (resolveSubgraph skipResolving) locators - if any resolutionFailed subgraphs - then fatalText $ resolveGraphFailureBundle subgraphs - else pure . mconcat $ fmap unwrap subgraphs + let (warned, success) = partitionMap partitionSubgraph subgraphs + renderWarnings warned + pure $ mconcat success where - resolutionFailed (_, b) = isNothing b - unwrap (_, b) = fromMaybe empty b + renderWarnings subgraphs = unless (null subgraphs) . warn $ resolveGraphFailureBundle subgraphs + partitionSubgraph (a, Nothing) = Left a + partitionSubgraph (_, Just b) = Right b -resolveGraphFailureBundle :: [(VSI.Locator, Maybe (Graphing VSI.Locator))] -> Text +resolveGraphFailureBundle :: [VSI.Locator] -> Text resolveGraphFailureBundle subgraphs = "Failed to resolve dependencies for the following FOSSA projects:\n\t" - <> intercalate "\n\t" (renderFailed subgraphs) + <> intercalate "\n\t" (fmap VSI.renderLocator subgraphs) <> "\n\n" - <> "You may not have access to the projects, or they may not exist (see the warnings below for details).\n" - <> "If desired you can use --experimental-skip-vsi-graph to skip resolving the dependencies of these projects." - where - renderFailed [] = [] - renderFailed ((a, b) : xs) = case b of - Just _ -> renderFailed xs - Nothing -> VSI.renderLocator a : renderFailed xs + <> "You may not have access to the projects, or they may not exist.\n" -- | Given a traverseable list and a monadic function that resolves them to b, traverse and zip the list into a pair of (a, b) traverseZipM :: (Traversable t, Applicative m) => (a -> m b) -> t a -> m (t (a, b)) traverseZipM f = traverse (\a -> (a,) <$> f a) +-- | Split the list into two mapped lists based on the predicate. +partitionMap :: (a -> Either b c) -> [a] -> ([b], [c]) +partitionMap split items = partitionEithers $ map split items + -- Pass through the list of skipped locators all the way here: -- we want to still record the direct dependency, we just don't want to resolve it. resolveSubgraph :: (Has FossaApiClient sig m, Has Diagnostics sig m) => VSI.SkipResolution -> VSI.Locator -> m (Maybe (Graphing VSI.Locator))