Skip to content

Commit

Permalink
Pre merge cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nmattia committed Jun 12, 2019
1 parent 43d7884 commit 567bdb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
26 changes: 0 additions & 26 deletions src/Niv/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import qualified Data.ByteString.Lazy as L
import qualified Data.HashMap.Strict as HMS
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified GitHub as GH
import qualified Options.Applicative as Opts
import qualified Options.Applicative.Help.Pretty as Opts
import qualified System.Directory as Dir
Expand Down Expand Up @@ -546,31 +545,6 @@ pathNixSourcesJson = "nix" </> "sources.json"
initNixSourcesJsonContent :: B.ByteString
initNixSourcesJsonContent = "{}"

-------------------------------------------------------------------------------
-- Warn
-------------------------------------------------------------------------------

warnCouldNotFetchGitHubRepo :: GH.Error -> (String, String) -> IO ()
warnCouldNotFetchGitHubRepo e (owner, repo) =
putStrLn $ unlines [ line1, line2, line3 ]
where
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
line2 = [s|
I assumed that your package was a GitHub repository. An error occurred while
gathering information from the repository. Check whether your package was added
correctly:

niv show

If not, try re-adding it:

niv drop <package>
niv add <package-without-typo>

Make sure the repository exists.
|]
line3 = unwords [ "(Error was:", show e, ")" ]

-------------------------------------------------------------------------------
-- Abort
-------------------------------------------------------------------------------
Expand Down
28 changes: 27 additions & 1 deletion src/Niv/GitHub.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{-# LANGUAGE Arrows #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}

module Niv.GitHub where

import Control.Arrow
import Data.Bool
import Data.Maybe
import Data.String.QQ (s)
import GHC.Exts (toList)
import Niv.Update
import qualified Data.Text as T
Expand All @@ -23,7 +26,9 @@ data GithubRepo = GithubRepo
githubRepo :: T.Text -> T.Text -> IO GithubRepo
githubRepo owner repo = fmap translate <$>
GH.executeRequest' (GH.repositoryR (GH.N owner) (GH.N repo)) >>= \case
Left e -> error (show e)
Left e -> do
warnCouldNotFetchGitHubRepo e (owner, repo)
error (show e)
Right x -> pure x
where
translate r = GithubRepo
Expand All @@ -32,6 +37,27 @@ githubRepo owner repo = fmap translate <$>
, repoDefaultBranch = GH.repoDefaultBranch r
}

warnCouldNotFetchGitHubRepo :: GH.Error -> (T.Text, T.Text) -> IO ()
warnCouldNotFetchGitHubRepo e (T.unpack -> owner, T.unpack -> repo) =
putStrLn $ unlines [ line1, line2, line3 ]
where
line1 = "WARNING: Could not read from GitHub repo: " <> owner <> "/" <> repo
line2 = [s|
I assumed that your package was a GitHub repository. An error occurred while
gathering information from the repository. Check whether your package was added
correctly:

niv show

If not, try re-adding it:

niv drop <package>
niv add <package-without-typo>

Make sure the repository exists.
|]
line3 = unwords [ "(Error was:", show e, ")" ]

-- TODO: fetchers for:
-- * npm
-- * hackage
Expand Down
1 change: 0 additions & 1 deletion src/Niv/Update.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ runUpdate (boxAttrs -> attrs) a = runUpdate' attrs a >>= feed
UpdateNeedMore next -> next (()) >>= hndl
hndl = \case
UpdateSuccess f v -> (,v) <$> unboxAttrs f
-- TODO: fix this
UpdateFailed e -> error $ "Update failed: " <> T.unpack (prettyFail e)
prettyFail :: UpdateFailed -> T.Text
prettyFail = \case
Expand Down

0 comments on commit 567bdb2

Please sign in to comment.