on master help sign in
add error handling in place of use of head
commit4627ae67e86c1ebb00476da84d5521d454b5e8e2 authorhsloan <ishaqsloan@gmail.com> dateFri 30 Nov 2018, 22:28 (8 years ago) parent1d2ea59
2 files changed+17−12
lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command/Thunk.hs+16−12
lib/command/obelisk-command.cabal+1
@@ -19,6 +19,7 @@ library
1919 , data-default
2020 , directory
2121 , either
22+ , errors
2223 , filepath
2324 , github
2425 , here
lib/command/src/Obelisk/Command/Thunk.hs+16−12
@@ -34,6 +34,7 @@ module Obelisk.Command.Thunk
3434
3535import Control.Applicative
3636import Control.Exception (displayException, try)
37+import Control.Error.Safe
3738import qualified Control.Lens as Lens
3839import Control.Lens.Indexed hiding ((<.>))
3940import Control.Monad
@@ -641,19 +642,22 @@ setThunk branch thunkDir = checkThunkDirectory thunkDir >> readThunk thunkDir >>
641642 ExitSuccess -> do
642643 remoteResults <- readGitProcessNoRepo ["ls-remote", repository, branch]
643644 uri <- mkURI $ T.pack repository
644− let rev = head $ T.words remoteResults -- TODO: Don't use head
645− sha256 <- nixPrefetchGit uri rev False
646− let newThunkPtr = ThunkPtr
647− { _thunkPtr_source = case _thunkPtr_source thunkptr of
648− ThunkSource_Git gitSource -> ThunkSource_Git $ gitSource { _gitSource_branch = Just $ N $ T.pack branch }
649− ThunkSource_GitHub gitHubSource -> ThunkSource_GitHub $ gitHubSource { _gitHubSource_branch = Just $ N $ T.pack branch }
650− , _thunkPtr_rev = ThunkRev
651− { _thunkRev_commit = Ref.hash $ encodeUtf8 rev
652− , _thunkRev_nixSha256 = sha256
645+ let eitherrev = headErr "rev for branch cannot be found" $ T.words remoteResults -- TODO: Don't use head
646+ case eitherrev of
647+ Left notFound -> failWith notFound
648+ Right rev -> do
649+ sha256 <- nixPrefetchGit uri rev False
650+ let newThunkPtr = ThunkPtr
651+ { _thunkPtr_source = case _thunkPtr_source thunkptr of
652+ ThunkSource_Git gitSource -> ThunkSource_Git $ gitSource { _gitSource_branch = Just $ N $ T.pack branch }
653+ ThunkSource_GitHub gitHubSource -> ThunkSource_GitHub $ gitHubSource { _gitHubSource_branch = Just $ N $ T.pack branch }
654+ , _thunkPtr_rev = ThunkRev
655+ { _thunkRev_commit = Ref.hash $ encodeUtf8 rev
656+ , _thunkRev_nixSha256 = sha256
657+ }
653658 }
654− }
655− overwriteThunk thunkDir newThunkPtr
656− updateThunkToLatest thunkDir Nothing
659+ overwriteThunk thunkDir newThunkPtr
660+ updateThunkToLatest thunkDir Nothing
657661 ExitFailure errNum -> failWith $ T.pack $ if errNum == 2
658662 then "Error: branch not found"
659663 else ("Error Code: " <> show errNum <> "issue checking out the desired branch")