Skip to content

Commit 968ed2d

Browse files
authored
Convert MSB errors to warnings (#1469)
1 parent cc34d94 commit 968ed2d

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

Changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# FOSSA CLI Changelog
22

3+
4+
## 3.9.33
5+
6+
- MSB: Failure to resolve a linked project no longer causes the scan to fail ([[#1469](https://github.com/fossas/fossa-cli/pull/1469)]).
7+
38
## 3.9.32
49

510
- Platform Support: Add a binary for ARM64 Linux environments. ([#1465](https://github.com/fossas/fossa-cli/pull/1465))

src/App/Fossa/VSI/IAT/Resolve.hs

+17-17
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import App.Fossa.VSI.IAT.Types (
1313
import App.Fossa.VSI.IAT.Types qualified as IAT
1414
import App.Fossa.VSI.Types qualified as VSI
1515
import Control.Algebra (Has)
16-
import Control.Effect.Diagnostics (Diagnostics, context, fatalText, recover)
16+
import Control.Effect.Diagnostics (Diagnostics, context, recover, warn)
1717
import Control.Effect.FossaApiClient (FossaApiClient, resolveProjectDependencies, resolveUserDefinedBinary)
18-
import Data.Maybe (fromMaybe, isNothing)
18+
import Control.Monad (unless)
19+
import Data.Either (partitionEithers)
1920
import Data.String.Conversion (toText)
2021
import Data.Text (Text, intercalate)
21-
import Graphing (Graphing, direct, edges, empty)
22+
import Graphing (Graphing, direct, edges)
2223
import Srclib.Types (
2324
SourceUserDefDep (..),
2425
)
@@ -48,30 +49,29 @@ resolveGraph locators skipResolving = context ("Resolving graph for " <> toText
4849
-- This typically means that the user doesn't have access to the project, or the project doesn't exist.
4950
-- Collect failed locators and report them to the user, along with mitigation suggestions.
5051
subgraphs <- traverseZipM (resolveSubgraph skipResolving) locators
51-
if any resolutionFailed subgraphs
52-
then fatalText $ resolveGraphFailureBundle subgraphs
53-
else pure . mconcat $ fmap unwrap subgraphs
52+
let (warned, success) = partitionMap partitionSubgraph subgraphs
53+
renderWarnings warned
54+
pure $ mconcat success
5455
where
55-
resolutionFailed (_, b) = isNothing b
56-
unwrap (_, b) = fromMaybe empty b
56+
renderWarnings subgraphs = unless (null subgraphs) . warn $ resolveGraphFailureBundle subgraphs
57+
partitionSubgraph (a, Nothing) = Left a
58+
partitionSubgraph (_, Just b) = Right b
5759

58-
resolveGraphFailureBundle :: [(VSI.Locator, Maybe (Graphing VSI.Locator))] -> Text
60+
resolveGraphFailureBundle :: [VSI.Locator] -> Text
5961
resolveGraphFailureBundle subgraphs =
6062
"Failed to resolve dependencies for the following FOSSA projects:\n\t"
61-
<> intercalate "\n\t" (renderFailed subgraphs)
63+
<> intercalate "\n\t" (fmap VSI.renderLocator subgraphs)
6264
<> "\n\n"
63-
<> "You may not have access to the projects, or they may not exist (see the warnings below for details).\n"
64-
<> "If desired you can use --experimental-skip-vsi-graph to skip resolving the dependencies of these projects."
65-
where
66-
renderFailed [] = []
67-
renderFailed ((a, b) : xs) = case b of
68-
Just _ -> renderFailed xs
69-
Nothing -> VSI.renderLocator a : renderFailed xs
65+
<> "You may not have access to the projects, or they may not exist.\n"
7066

7167
-- | Given a traverseable list and a monadic function that resolves them to b, traverse and zip the list into a pair of (a, b)
7268
traverseZipM :: (Traversable t, Applicative m) => (a -> m b) -> t a -> m (t (a, b))
7369
traverseZipM f = traverse (\a -> (a,) <$> f a)
7470

71+
-- | Split the list into two mapped lists based on the predicate.
72+
partitionMap :: (a -> Either b c) -> [a] -> ([b], [c])
73+
partitionMap split items = partitionEithers $ map split items
74+
7575
-- Pass through the list of skipped locators all the way here:
7676
-- we want to still record the direct dependency, we just don't want to resolve it.
7777
resolveSubgraph :: (Has FossaApiClient sig m, Has Diagnostics sig m) => VSI.SkipResolution -> VSI.Locator -> m (Maybe (Graphing VSI.Locator))

test/App/Fossa/VSI/IAT/ResolveSpec.hs

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import DepTypes (DepType (CustomType))
1010
import Graphing qualified
1111
import Srclib.Converter (depTypeToFetcher)
1212
import Srclib.Types (SourceUserDefDep (..))
13-
import Test.Effect (expectFatal', it', shouldBe')
13+
import Test.Effect (it', shouldBe')
1414
import Test.Hspec (Spec, describe)
1515
import Test.MockApi (fails, returnsOnce)
1616

@@ -47,17 +47,22 @@ spec = do
4747
maybeDeps <- resolveRevision package
4848
maybeDeps `shouldBe'` Just [dep1, dep2]
4949
describe "resolveGraph" $ do
50-
it' "dies if resolving any subgraph fails to resolve" $ do
50+
it' "resolves available subgraphs" $ do
5151
let package1 = testTopLevelLocator 1
5252
package2 = testTopLevelLocator 2
5353
dep1 = testLocator 11
5454
dep2 = testLocator 12
5555
skips = SkipResolution (Set.empty)
56+
expectedGraph =
57+
Graphing.directs [package1]
58+
<> Graphing.edges [(package1, dep1), (package1, dep2)]
5659
-- Package1 is fine
5760
ResolveProjectDependencies package1 `returnsOnce` [dep1, dep2]
5861
-- Package2 has an error
5962
ResolveProjectDependencies package2 `fails` "Mock error"
60-
expectFatal' $ resolveGraph [package1, package2] skips
63+
-- The graph should resolve with the successful results.
64+
graph <- resolveGraph [package1, package2] skips
65+
graph `shouldBe'` expectedGraph
6166
it' "resolves dependencies not in the skip list" $ do
6267
let package1 = testTopLevelLocator 1
6368
package2 = testTopLevelLocator 2

0 commit comments

Comments
 (0)