diff --git a/src/Main.hs b/src/Main.hs index c8e09d7..a58a145 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,10 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} +import Control.Exception import qualified Data.Text as T import Shelly import Prelude hiding (log) -import Utils (Options(..), Version, setupNixpkgs, parseUpdates, tRead) +import Utils (Options(..), Version, ExitCode(..), setupNixpkgs, parseUpdates, tRead, canFail) import Data.Text (Text) import Data.Maybe (isJust) import Update (updatePackage) @@ -56,7 +57,13 @@ loop _ log [] _ = log "ups.sh finished" loop options log ((package, oldVersion, newVersion) : moreUpdates) okToPrAt = do log package - updated <- updatePackage options package oldVersion newVersion okToPrAt + updated <- catch_sh + (updatePackage options package oldVersion newVersion okToPrAt) + (\ e -> + case e of + ExitCode 0 -> return True + ExitCode _ -> return False + _ -> throw e) okToPrAt <- if updated then do diff --git a/src/Update.hs b/src/Update.hs index 4419024..3b7f6f0 100644 --- a/src/Update.hs +++ b/src/Update.hs @@ -4,12 +4,13 @@ module Update (updatePackage) where +import Control.Exception (throw) import qualified Data.Text as T import Data.Text (Text) import Data.Maybe (fromMaybe) import Shelly import Check (checkResult) -import Utils (Version, Options(..), canFail, orElse, setupNixpkgs, tRead, checkAttrPathVersion) +import Utils (Version, Options(..), ExitCode(..), canFail, orElse, setupNixpkgs, tRead, checkAttrPathVersion) import Data.Semigroup ((<>)) default (T.Text) @@ -25,7 +26,7 @@ errorExit' :: Text -> Text -> Sh a errorExit' branchName message = do cleanup branchName echo $ "$(date -Iseconds) " <> message - exit 1 + throw (ExitCode 1) isOnBlackList :: (Text -> Sh Text) -> Text -> Sh Text isOnBlackList errorExit packageName @@ -230,4 +231,4 @@ updatePackage options packageName oldVersion newVersion okToPrAt = do cmd "git" "reset" "--hard" cmd "git" "clean" "-fd" - exit 0 + return True diff --git a/src/Utils.hs b/src/Utils.hs index 973899e..a61484b 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -1,9 +1,10 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ExtendedDefaultRules #-} {-# OPTIONS_GHC -fno-warn-type-defaults #-} -module Utils (Options(..), Version, canFail, checkAttrPathVersion, orElse, setupNixpkgs, tRead, parseUpdates, succeded) where +module Utils (Options(..), Version, canFail, checkAttrPathVersion, orElse, setupNixpkgs, tRead, parseUpdates, succeded, ExitCode(..)) where import Prelude hiding (FilePath) +import Control.Exception (Exception) import Data.Text (Text) import Data.Semigroup ((<>)) import qualified Data.Text as T @@ -147,3 +148,5 @@ checkAttrPathVersion attrPath newVersion = in attrVersionPart `isNonEmptyPrefixOf` noPeriodNewVersion +data ExitCode = ExitCode Int deriving (Show) +instance Exception ExitCode