Skip to content

Commit

Permalink
get rid of most of utils.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Sep 20, 2023
1 parent fc71a51 commit 38f7398
Show file tree
Hide file tree
Showing 18 changed files with 409 additions and 521 deletions.
3 changes: 3 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ You can edit this file as you like.
, "datetime"
, "effect"
, "either"
, "errors"
, "eth-core"
, "exceptions"
, "foldable-traversable"
, "foreign-object"
, "functors"
, "identity"
, "integers"
, "js-date"
, "logging"
, "maybe"
, "mkdirp"
Expand All @@ -33,6 +35,7 @@ You can edit this file as you like.
, "node-fs-aff"
, "node-path"
, "node-process"
, "now"
, "optparse"
, "ordered-collections"
, "parallel"
Expand Down
21 changes: 12 additions & 9 deletions src/Chanterelle.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ module Chanterelle where

import Prelude

import Chanterelle.Compile (compile) as Chanterelle
import Chanterelle.Deploy (deploy)
import Chanterelle.Internal.Codegen (generatePS) as Chanterelle
import Chanterelle.Internal.Compile (compile) as Chanterelle
import Chanterelle.Logging (LogLevel(..), log, logCompileError, readLogLevel, setLogLevel)
import Chanterelle.Project (loadProject)
import Chanterelle.Types.Compile (runCompileM)
import Chanterelle.Types.Deploy (DeployM)
import Chanterelle.Types.Compile (runCompileMExceptT)
import Chanterelle.Types.Project (ChanterelleProject)
import Chanterelle.Internal.Utils (eitherM_)
import Chanterelle.Project (loadProject)
import Control.Monad.Error.Class (try)
import Data.Either (Either(..))
import Data.Either (Either(..), either)
import Data.Generic.Rep (class Generic)
import Data.Show.Generic (genericShow)
import Effect.Aff (Aff)
Expand Down Expand Up @@ -45,7 +44,7 @@ data CommonOpts = CommonOpts
}

derive instance Generic CommonOpts _
instance showCommonOpts :: Show CommonOpts where
instance Show CommonOpts where
show = genericShow

data Command s
Expand All @@ -56,7 +55,7 @@ data Command s
| GlobalDeploy (DeployOptions s)

derive instance Generic (Command s) _
instance showCommand :: Show (DeployOptions s) => Show (Command s) where
instance Show (DeployOptions s) => Show (Command s) where
show = genericShow

traverseDeployOptions :: forall a b f. Applicative f => (DeployOptions a -> f (DeployOptions b)) -> Args' a -> f (Args' b)
Expand Down Expand Up @@ -104,7 +103,11 @@ runCommand project = case _ of
log Error $ "deploy is unavailable as Chanterelle is running from a global installation"
log Error $ "Please ensure your project's Chanterelle instance has compiled"
-- doClassicBuild = doCompile *> doCodegen
doCompile = eitherM_ terminateOnCompileError $ runCompileMExceptT Chanterelle.compile project
doCodegen = eitherM_ terminateOnCompileError $ runCompileMExceptT Chanterelle.generatePS project
doCompile = do
eRes <- runCompileM Chanterelle.compile project
either terminateOnCompileError mempty eRes
doCodegen = do
eRes <- runCompileM Chanterelle.generatePS project
either terminateOnCompileError mempty eRes

terminateOnCompileError e = logCompileError e *> liftEffect (exit 1)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Chanterelle.Internal.Artifact
module Chanterelle.Artifact
( readArtifact
, updateArtifact
, writeArtifact
Expand All @@ -7,8 +7,7 @@ module Chanterelle.Internal.Artifact
import Prelude

import Chanterelle.Types.Artifact (Artifact(..))
import Chanterelle.Internal.Utils.FS (readTextFile, withTextFile, writeTextFile)
import Chanterelle.Internal.Utils.Json (jsonStringifyWithSpaces, parseDecodeM)
import Chanterelle.Utils (jsonStringifyWithSpaces, parseDecodeM, readTextFile, withTextFile, writeTextFile)
import Control.Monad.Error.Class (class MonadThrow)
import Data.Argonaut (encodeJson)
import Data.DateTime.Instant (unInstant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Prelude
import Chanterelle.Logging (LogLevel(..), log)
import Chanterelle.Types.Compile (CompileError(..))
import Chanterelle.Types.Project (ChanterelleProject(..), ChanterelleProjectSpec(..), ChanterelleModule(..))
import Chanterelle.Internal.Utils.FS (assertDirectory')
import Chanterelle.Utils (assertDirectory')
import Control.Monad.Error.Class (class MonadThrow, throwError)
import Control.Monad.Reader (class MonadAsk, ask)
import Data.AbiParser (Abi(Abi), AbiDecodeError(..), AbiWithErrors) as PSWeb3Gen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Chanterelle.Internal.Compile
module Chanterelle.Compile
( compile
, makeSolcInput
, compileModuleWithoutWriting
Expand All @@ -8,14 +8,14 @@ module Chanterelle.Internal.Compile

import Prelude

import Chanterelle.Internal.Artifact (writeArtifact)
import Chanterelle.Internal.Utils.Error (withExcept', withExceptM', withExceptT')
import Chanterelle.Internal.Utils.FS (assertDirectory', fileIsDirty)
import Chanterelle.Artifact (writeArtifact)
import Chanterelle.Logging (LogLevel(..), log, logSolcError)
import Chanterelle.Types.Artifact (Artifact(..))
import Chanterelle.Types.Bytecode (Bytecode(..), flattenLinkReferences)
import Chanterelle.Types.Compile (CompileError(..))
import Chanterelle.Types.Project (ChanterelleModule(..), ChanterelleProject(..), ChanterelleProjectSpec(..), Dependency(..), getSolc, partitionSelectionSpecs)
import Chanterelle.Utils (assertDirectory', fileIsDirty)
import Chanterelle.Utils.Error (withExceptT')
import Control.Error.Util (note)
import Control.Monad.Error.Class (class MonadThrow, throwError)
import Control.Monad.Reader (class MonadAsk, ask)
Expand All @@ -24,7 +24,7 @@ import Data.Argonaut as A
import Data.Argonaut.Parser as AP
import Data.Array (catMaybes, partition)
import Data.Bifunctor (lmap)
import Data.Either (Either(..), hush)
import Data.Either (Either(..), either, hush)
import Data.Lens ((^?))
import Data.Lens.Index (ix)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
Expand Down Expand Up @@ -113,7 +113,9 @@ compileModuleWithoutWriting
-> m ST.CompilerOutput
compileModuleWithoutWriting m@(ChanterelleModule mod) solcInput = do
(ChanterelleProject project) <- ask
solc <- withExceptM' CompilerUnavailable $ getSolc project.solc
solc <- do
eRes <- getSolc project.solc
either (throwError <<< CompilerUnavailable) pure eRes
log Info ("compiling " <> show mod.moduleType <> " " <> mod.moduleName)
output <- Solc.compile solc solcInput (loadSolcCallback m project.root project.spec) --liftEffect $ runFn2 _compile (A.stringify $ encodeJson solcInput) (loadSolcCallback m project.root project.spec)
case output of
Expand Down Expand Up @@ -243,7 +245,8 @@ resolveSolidityContractLevelOutput
. MonadThrow CompileError m
=> ST.ContractLevelOutput
-> m Artifact
resolveSolidityContractLevelOutput = withExcept' UnexpectedSolcOutput <<< fromSolidityContractLevelOutput
resolveSolidityContractLevelOutput a =
either (throwError <<< UnexpectedSolcOutput) pure $ fromSolidityContractLevelOutput a
where

fromSolidityBytecodeOutput :: ST.BytecodeOutput -> Either String Bytecode
Expand Down
Loading

0 comments on commit 38f7398

Please sign in to comment.