diff --git a/src/Spago/Command/Fetch.purs b/src/Spago/Command/Fetch.purs index 953bc9f0e..965726365 100644 --- a/src/Spago/Command/Fetch.purs +++ b/src/Spago/Command/Fetch.purs @@ -519,6 +519,14 @@ getGitPackageInLocalCache name package = do getPackageDependencies :: forall a. PackageName -> Package -> Spago (FetchEnv a) (Maybe (ByEnv (Map PackageName Range))) getPackageDependencies packageName package = case package of RegistryVersion v -> do + -- Check if registry-index exists when offline + whenM (asks _.offline <#> eq Offline) do + unlessM (FS.exists Paths.registryIndexPath) do + die + [ "You are offline and the Registry Index is not cached locally." + , "Cannot look up dependencies for " <> PackageName.print packageName <> "@" <> Version.print v + , "Please connect to the internet and run 'spago install' first." + ] maybeManifest <- Registry.getManifestFromIndex packageName v pure $ maybeManifest <#> \(Manifest m) -> { core: m.dependencies, test: Map.empty } GitPackage p -> do diff --git a/src/Spago/Git.purs b/src/Spago/Git.purs index 140136176..a68ca5514 100644 --- a/src/Spago/Git.purs +++ b/src/Spago/Git.purs @@ -97,9 +97,15 @@ checkout { repo, ref } = Except.runExceptT $ void $ runGit [ "checkout", ref ] ( fetch :: ∀ a path. Path.IsPath path => { repo :: path, remote :: String } -> Spago (GitEnv a) (Either String Unit) fetch { repo, remote } = do - remoteUrl <- runGit [ "remote", "get-url", remote ] (Just $ Path.toGlobal repo) # Except.runExceptT >>= rightOrDie - logInfo $ "Fetching from " <> remoteUrl - Except.runExceptT $ runGit_ [ "fetch", remote, "--tags" ] (Just $ Path.toGlobal repo) + { offline } <- ask + case offline of + Offline -> do + logDebug $ "Skipping fetch from remote '" <> remote <> "' because we are offline" + pure $ Left "Cannot fetch from remote while offline." + _ -> do + remoteUrl <- runGit [ "remote", "get-url", remote ] (Just $ Path.toGlobal repo) # Except.runExceptT >>= rightOrDie + logInfo $ "Fetching from " <> remoteUrl + Except.runExceptT $ runGit_ [ "fetch", remote, "--tags" ] (Just $ Path.toGlobal repo) getRefType :: ∀ a path. Path.IsPath path => { repo :: path, ref :: String } -> Spago (GitEnv a) (Either String String) getRefType { repo, ref } = Except.runExceptT $ runGit [ "cat-file", "-t", ref ] (Just $ Path.toGlobal repo) diff --git a/src/Spago/Registry.purs b/src/Spago/Registry.purs index c9ef7ed29..b70b31f5b 100644 --- a/src/Spago/Registry.purs +++ b/src/Spago/Registry.purs @@ -188,6 +188,16 @@ getRegistryFns registryBox registryLock = do -- Now that we are up to date with the Registry we init/refresh the database updatePackageSetsDb db + + -- Check if registry directories exist when offline - the build should have already failed by now, but just in case.. + case offline of + Offline -> do + unlessM (FS.exists Paths.registryPath) $ + die "You are offline and the Registry is not cached locally. Please connect to the internet and run 'spago install' to cache the registry." + unlessM (FS.exists Paths.registryIndexPath) $ + die "You are offline and the Registry Index is not cached locally. Please connect to the internet and run 'spago install' to cache the registry index." + _ -> pure unit + pure fetchingFreshRegistry -- | Update the database with the latest package sets @@ -211,12 +221,19 @@ getRegistryFns registryBox registryLock = do -- | List all the package sets versions available in the Registry repo getAvailablePackageSets :: ∀ a. Spago (LogEnv a) (Array Version) getAvailablePackageSets = do - { success: setVersions, fail: parseFailures } <- map (partitionEithers <<< map parseSetVersion) $ FS.ls Paths.packageSetsPath - - unless (Array.null parseFailures) do - logDebug $ [ toDoc "Failed to parse some package-sets versions:" ] <> map (indent <<< toDoc <<< show) parseFailures - - pure setVersions + packageSetsExists <- FS.exists Paths.packageSetsPath + if packageSetsExists then do + { success: setVersions, fail: parseFailures } <- map (partitionEithers <<< map parseSetVersion) $ FS.ls Paths.packageSetsPath + + unless (Array.null parseFailures) do + logDebug $ [ toDoc "Failed to parse some package-sets versions:" ] <> map (indent <<< toDoc <<< show) parseFailures + + pure setVersions + else do + die + [ "Package sets directory does not exist at " <> Path.quote Paths.packageSetsPath + , "Please connect to the internet and run 'spago install' to populate the registry cache." + ] where parseSetVersion str = Version.parse case String.stripSuffix (Pattern ".json") str of Nothing -> str @@ -286,7 +303,7 @@ getManifestFromIndexImpl db name version = do manifests <- map (map (\m@(Manifest m') -> Tuple m'.version m)) case maybeManifests of Right ms -> pure $ NonEmptyArray.toUnfoldable ms Left err -> do - logWarn $ "Could not read package manifests from index, proceeding anyways. Error: " <> err + logWarn $ "Could not read package manifests for '" <> PackageName.print name <> "' from index. Error: " <> err pure [] let versions = Map.fromFoldable manifests -- and memoize it