Skip to content

Commit

Permalink
Rename ContractError to PreconditionFailed (#9782)
Browse files Browse the repository at this point in the history
* Rename ContractError to PreconditionFailed

Part of #8020

changelog_begin
changelog_end

* Packaging.hs mistake
  • Loading branch information
sofiafaro-da authored May 25, 2021
1 parent 1b428be commit cd2ed07
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ generateStablePackages lfVersion fp = do
, "DA-Internal-PromotedText.dalf"
, "DA-Exception-GeneralError.dalf"
, "DA-Exception-ArithmeticError.dalf"
, "DA-Exception-ContractError.dalf"
, "DA-Exception-AssertionFailed.dalf"
, "DA-Exception-PreconditionFailed.dalf"
, "DA-Types.dalf"
, "GHC-Prim.dalf"
, "GHC-Tuple.dalf"
Expand Down
4 changes: 2 additions & 2 deletions compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ convertTemplate env tplTypeCon tbinds@TemplateBinds{..}
ECase b
[ CaseAlternative (CPBool True) ETrue
, CaseAlternative (CPBool False)
$ EThrow TBool (TCon contractErrorTypeCon)
$ mkContractError
$ EThrow TBool (TCon preconditionFailedTypeCon)
$ mkPreconditionFailed
$ EBuiltin BEAppendText
`ETmApp` EBuiltin (BEText "Template precondition violated: " )
`ETmApp`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ mkBuiltinGreater v ty =
then EBuiltin BEGreaterGeneric `ETyApp` TBuiltin ty
else EBuiltin (BEGreater ty)

contractErrorTypeCon :: Qualified TypeConName
contractErrorTypeCon = Qualified
{ qualPackage = PRImport (PackageId "a4d351c1a14963402c98d9c4ad92ce7e7cea74d81138f4de012df8d65229b78f")
, qualModule = ModuleName ["DA", "Exception", "ContractError"]
, qualObject = TypeConName ["ContractError"]
preconditionFailedTypeCon :: Qualified TypeConName
preconditionFailedTypeCon = Qualified
{ qualPackage = PRImport (PackageId "dc9576d7b3a816944d0d07c7e2d57f8ebe247187f9e08629d6fa9b1020a77b5d")
, qualModule = ModuleName ["DA", "Exception", "PreconditionFailed"]
, qualObject = TypeConName ["PreconditionFailed"]
}

mkContractError :: Expr -> Expr
mkContractError msg = ERecCon
{ recTypeCon = TypeConApp contractErrorTypeCon []
mkPreconditionFailed :: Expr -> Expr
mkPreconditionFailed msg = ERecCon
{ recTypeCon = TypeConApp preconditionFailedTypeCon []
, recFields = [(FieldName "message", msg)]
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ preprocessorExceptions = Set.fromList $ map GHC.mkModuleName
, "DA.Exception"
, "DA.Exception.GeneralError"
, "DA.Exception.ArithmeticError"
, "DA.Exception.ContractError"
, "DA.Exception.AssertionFailed"
, "DA.Exception.PreconditionFailed"

-- These modules need to have the record preprocessor disabled.
, "DA.NonEmpty.Types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
#ifndef DAML_EXCEPTIONS

-- | HIDE
module DA.Exception.ContractError where
module DA.Exception.PreconditionFailed where

import GHC.Types ()

#else

-- | MOVE DA.Exception
module DA.Exception.ContractError where
module DA.Exception.PreconditionFailed where

import GHC.Types (Text)

-- | Exception raised when a contract is invalid, i.e. fails the ensure clause.
data ContractError = ContractError { message : Text }
data PreconditionFailed = PreconditionFailed { message : Text }

#endif
2 changes: 1 addition & 1 deletion compiler/damlc/daml-prim-src/LibraryModules.daml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ import GHC.Types
#ifdef DAML_EXCEPTIONS
import DA.Exception.GeneralError
import DA.Exception.ArithmeticError
import DA.Exception.ContractError
import DA.Exception.AssertionFailed
import DA.Exception.PreconditionFailed
#endif
24 changes: 12 additions & 12 deletions compiler/damlc/daml-stdlib-src/DA/Internal/Exception.daml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ module DA.Internal.Exception where
module DA.Internal.Exception
( module DA.Internal.Exception
, AnyException
, GeneralError (GeneralError)
, GeneralError (GeneralError)
, ArithmeticError (ArithmeticError)
, ContractError (ContractError)
, AssertionFailed (AssertionFailed)
, PreconditionFailed (PreconditionFailed)
) where

import GHC.Types
import DA.Exception.GeneralError ( GeneralError (GeneralError) )
import DA.Exception.GeneralError ( GeneralError (GeneralError) )
import DA.Exception.ArithmeticError ( ArithmeticError (ArithmeticError) )
import DA.Exception.ContractError ( ContractError (ContractError) )
import DA.Exception.AssertionFailed ( AssertionFailed (AssertionFailed) )
import DA.Exception.PreconditionFailed ( PreconditionFailed (PreconditionFailed) )
import DA.Internal.LF
import DA.Internal.Prelude
import DA.Internal.Record
Expand Down Expand Up @@ -123,20 +123,20 @@ instance HasFromAnyException ArithmeticError where

--------------------------------------------------------------

instance HasField "message" ContractError Text where
getField (ContractError m) = m
setField m (ContractError _) = ContractError m
instance HasField "message" PreconditionFailed Text where
getField (PreconditionFailed m) = m
setField m (PreconditionFailed _) = PreconditionFailed m

instance HasThrow ContractError where
instance HasThrow PreconditionFailed where
throwPure = primitive @"EThrow"

instance HasMessage ContractError where
message (ContractError m) = m
instance HasMessage PreconditionFailed where
message (PreconditionFailed m) = m

instance HasToAnyException ContractError where
instance HasToAnyException PreconditionFailed where
toAnyException = primitive @"EToAnyException"

instance HasFromAnyException ContractError where
instance HasFromAnyException PreconditionFailed where
fromAnyException e =
primitive @"EFromAnyException" e

Expand Down
2 changes: 1 addition & 1 deletion compiler/damlc/lib/DA/Cli/Damlc/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ baseImports =
, "DA.Internal.PromotedText"
, "DA.Exception.GeneralError"
, "DA.Exception.ArithmeticError"
, "DA.Exception.ContractError"
, "DA.Exception.AssertionFailed"
, "DA.Exception.PreconditionFailed"
, "GHC.Err"
, "Data.String"
]
Expand Down
6 changes: 3 additions & 3 deletions compiler/damlc/stable-packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ genrule(
"daml-prim/DA-Internal-PromotedText.dalf",
"daml-prim/DA-Exception-GeneralError.dalf",
"daml-prim/DA-Exception-ArithmeticError.dalf",
"daml-prim/DA-Exception-ContractError.dalf",
"daml-prim/DA-Exception-AssertionFailed.dalf",
"daml-prim/DA-Exception-PreconditionFailed.dalf",
"daml-prim/DA-Types.dalf",
"daml-stdlib/DA-Internal-Template.dalf",
"daml-stdlib/DA-Internal-Any.dalf",
Expand All @@ -75,8 +75,8 @@ genrule(
$(location :generate-stable-package) --module DA.Internal.PromotedText -o $(location daml-prim/DA-Internal-PromotedText.dalf)
$(location :generate-stable-package) --module DA.Exception.GeneralError -o $(location daml-prim/DA-Exception-GeneralError.dalf)
$(location :generate-stable-package) --module DA.Exception.ArithmeticError -o $(location daml-prim/DA-Exception-ArithmeticError.dalf)
$(location :generate-stable-package) --module DA.Exception.ContractError -o $(location daml-prim/DA-Exception-ContractError.dalf)
$(location :generate-stable-package) --module DA.Exception.AssertionFailed -o $(location daml-prim/DA-Exception-AssertionFailed.dalf)
$(location :generate-stable-package) --module DA.Exception.PreconditionFailed -o $(location daml-prim/DA-Exception-PreconditionFailed.dalf)
$(location :generate-stable-package) --module DA.Types -o $(location daml-prim/DA-Types.dalf)
$(location :generate-stable-package) --module DA.Time.Types -o $(location daml-stdlib/DA-Time-Types.dalf)
$(location :generate-stable-package) --module DA.NonEmpty.Types -o $(location daml-stdlib/DA-NonEmpty-Types.dalf)
Expand All @@ -101,8 +101,8 @@ filegroup(
srcs = [
"daml-prim/DA-Exception-ArithmeticError.dalf",
"daml-prim/DA-Exception-AssertionFailed.dalf",
"daml-prim/DA-Exception-ContractError.dalf",
"daml-prim/DA-Exception-GeneralError.dalf",
"daml-prim/DA-Exception-PreconditionFailed.dalf",
"daml-prim/DA-Internal-Erased.dalf",
"daml-prim/DA-Internal-PromotedText.dalf",
"daml-prim/DA-Types.dalf",
Expand Down
8 changes: 4 additions & 4 deletions compiler/damlc/stable-packages/lib/DA/Daml/StablePackages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ allStablePackages =
, daSetTypes
, daExceptionGeneralError
, daExceptionArithmeticError
, daExceptionContractError
, daExceptionAssertionFailed
, daExceptionPreconditionFailed
]

allStablePackagesForVersion :: Version -> [Package]
Expand Down Expand Up @@ -553,12 +553,12 @@ daExceptionGeneralError = builtinExceptionPackage "GeneralError"
daExceptionArithmeticError :: Package
daExceptionArithmeticError = builtinExceptionPackage "ArithmeticError"

daExceptionContractError :: Package
daExceptionContractError = builtinExceptionPackage "ContractError"

daExceptionAssertionFailed :: Package
daExceptionAssertionFailed = builtinExceptionPackage "AssertionFailed"

daExceptionPreconditionFailed :: Package
daExceptionPreconditionFailed = builtinExceptionPackage "PreconditionFailed"

builtinExceptionPackage :: T.Text -> Package
builtinExceptionPackage name = Package
{ packageLfVersion = featureMinVersion featureExceptions
Expand Down
4 changes: 2 additions & 2 deletions compiler/damlc/tests/daml-test-files/ExceptionCreate.daml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

-- @SINCE-LF 1.dev

-- | Test that create throws a ContractError when the precondition is violated.
-- | Test that create throws a PreconditionFailed when the precondition is violated.
module ExceptionCreate where

import DA.Assert
Expand All @@ -23,6 +23,6 @@ test = scenario do
create (MyTemplate p)
pure ""
catch
ContractError msg ->
PreconditionFailed msg ->
pure msg
m === "Template precondition violated: MyTemplate {p = 'Alice'}"
2 changes: 1 addition & 1 deletion compiler/damlc/tests/src/stable-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ $DIFF -u -b <($DAMLC inspect-dar $DIR/out.dar | sed '1,/following packages/d' |
daml-prim-DA-Exception-ArithmeticError-f1cf1ff41057ce327248684089b106d0a1f27c2f092d30f663c919addf173981 "f1cf1ff41057ce327248684089b106d0a1f27c2f092d30f663c919addf173981"
daml-prim-DA-Exception-AssertionFailed-0b6d5242cee0f53a6aa39ab7caa8122e3864b200b86338007b334b0ad3c65830 "0b6d5242cee0f53a6aa39ab7caa8122e3864b200b86338007b334b0ad3c65830"
daml-prim-DA-Exception-ContractError-a4d351c1a14963402c98d9c4ad92ce7e7cea74d81138f4de012df8d65229b78f "a4d351c1a14963402c98d9c4ad92ce7e7cea74d81138f4de012df8d65229b78f"
daml-prim-DA-Exception-GeneralError-a4c4df2bd621b1bc1ba9fb5d3e633a5ddffb5b59e379bb091a18ce3f7801a7e4 "a4c4df2bd621b1bc1ba9fb5d3e633a5ddffb5b59e379bb091a18ce3f7801a7e4"
daml-prim-DA-Exception-PreconditionFailed-dc9576d7b3a816944d0d07c7e2d57f8ebe247187f9e08629d6fa9b1020a77b5d "dc9576d7b3a816944d0d07c7e2d57f8ebe247187f9e08629d6fa9b1020a77b5d"
daml-prim-DA-Internal-Erased-76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f "76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f"
daml-prim-DA-Internal-PromotedText-d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97 "d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97"
daml-prim-DA-Types-40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7 "40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7"
Expand Down

0 comments on commit cd2ed07

Please sign in to comment.