From 92d0d437c018b69f3ccf40ab0f82d9d07cae6041 Mon Sep 17 00:00:00 2001 From: Carl Pulley <106966370+carlpulley-da@users.noreply.github.com> Date: Tue, 12 Nov 2024 12:12:34 +0000 Subject: [PATCH] UP-18: daml-script upgrade error piping (#20255) * UP-18: daml-script upgrade error piping --- .../Internal/Questions/Submit/Error.daml | 5 ++++- .../v2/ledgerinteraction/SubmitError.scala | 19 +++++-------------- .../test/daml/upgrades/ContractKeys.daml | 2 +- sdk/daml-script/test/daml/upgrades/Fetch.daml | 2 +- .../test/daml/upgrades/FromInterface.daml | 2 +- .../test/daml/upgrades/InterfaceViews.daml | 6 +++--- .../upgrades/SignatoryObserverChanges.daml | 2 +- .../test/daml/upgrades/VariantChanges.daml | 2 +- 8 files changed, 17 insertions(+), 23 deletions(-) diff --git a/sdk/daml-script/daml3/Daml/Script/Internal/Questions/Submit/Error.daml b/sdk/daml-script/daml3/Daml/Script/Internal/Questions/Submit/Error.daml index 28b3f1d5ca4e..9eef72753f3c 100644 --- a/sdk/daml-script/daml3/Daml/Script/Internal/Questions/Submit/Error.daml +++ b/sdk/daml-script/daml3/Daml/Script/Internal/Questions/Submit/Error.daml @@ -18,7 +18,6 @@ import DA.Exception data DevErrorType = ChoiceGuardFailed | WronglyTypedContractSoft - | Upgrade | UnknownNewFeature -- ^ This should never happen - Update Scripts when you see this! deriving Show @@ -127,6 +126,9 @@ data SubmitError LocalVerdictLockedKeys with localVerdictLockedKeys : [AnyContractKey] -- ^ Locked contract keys + | -- | Upgrade exception + UpgradeError with -- We just give the error's prettied message. Scripts doesn't need anything more right now. + errorMessage : Text | -- | Development feature exceptions DevError with -- We just give the error's simple class name and the prettied message it generates. Scripts doesn't need anything more right now. devErrorType : DevErrorType @@ -177,6 +179,7 @@ instance Show SubmitError where ValueNesting limit -> "Exceeded maximum nesting depth for values - limit: " <> show limit LocalVerdictLockedContracts cids -> "Attempted to use locked contracts: " <> show cids LocalVerdictLockedKeys _ -> "Attempted to use locked contract keys" + UpgradeError msg -> "UpgradeError: \"" <> msg <> "\"" DevError ty msg -> "DevError of type " <> show ty <> " and message \"" <> msg <> "\"" UnknownError msg -> "Unknown error: " <> msg TruncatedError ty msg -> "TruncatedError of type " <> ty <> " and message \"" <> msg <> "\"" diff --git a/sdk/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/v2/ledgerinteraction/SubmitError.scala b/sdk/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/v2/ledgerinteraction/SubmitError.scala index 1f899188fa90..2ef1890c8792 100644 --- a/sdk/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/v2/ledgerinteraction/SubmitError.scala +++ b/sdk/daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/v2/ledgerinteraction/SubmitError.scala @@ -404,20 +404,11 @@ class SubmitErrors(majorLanguageVersion: LanguageMajorVersion) { } sealed case class UpgradeError(message: String) extends SubmitError { - // TODO https://github.com/digital-asset/daml/issues/18616: use a non-Dev based error code override def toDamlSubmitError(env: Env): SValue = { - val upgradeErrorTypeIdentifier = - env.scriptIds.damlScriptModule( - "Daml.Script.Internal.Questions.Submit.Error", - "DevErrorType", - ) - val upgradeErrorType = SEnum(upgradeErrorTypeIdentifier, Name.assertFromString("Upgrade"), 2) - SubmitErrorConverters(env).damlScriptError( - "DevError", + "UpgradeError", 20, - ("devErrorType", upgradeErrorType), - ("devErrorMessage", SText(message)), + ("errorMessage", SText(message)), ) } } @@ -439,7 +430,7 @@ class SubmitErrors(majorLanguageVersion: LanguageMajorVersion) { } SubmitErrorConverters(env).damlScriptError( "DevError", - 20, + 21, ("devErrorType", devErrorType), ("devErrorMessage", SText(message)), ) @@ -450,7 +441,7 @@ class SubmitErrors(majorLanguageVersion: LanguageMajorVersion) { override def toDamlSubmitError(env: Env): SValue = SubmitErrorConverters(env).damlScriptError( "UnknownError", - 21, + 22, ("unknownErrorMessage", SText(message)), ) } @@ -459,7 +450,7 @@ class SubmitErrors(majorLanguageVersion: LanguageMajorVersion) { override def toDamlSubmitError(env: Env): SValue = SubmitErrorConverters(env).damlScriptError( "TruncatedError", - 22, + 23, ("truncatedErrorType", SText(errType)), ("truncatedErrorMessage", SText(message)), ) diff --git a/sdk/daml-script/test/daml/upgrades/ContractKeys.daml b/sdk/daml-script/test/daml/upgrades/ContractKeys.daml index 1f675b7ea0f4..bf39939bf5ef 100644 --- a/sdk/daml-script/test/daml/upgrades/ContractKeys.daml +++ b/sdk/daml-script/test/daml/upgrades/ContractKeys.daml @@ -658,7 +658,7 @@ exerciseUpdateKeyUpgraded = test $ do expectMetadataChangedError : Either SubmitError a -> Script () expectMetadataChangedError r = case r of Right _ -> assertFail "Expected failure but got success" - Left (DevError Upgrade msg) + Left (UpgradeError msg) | "Verify that neither the signatories, nor the observers, nor the contract key, nor the key's maintainers have changed" `isInfixOf` msg -> pure () Left e -> assertFail $ "Expected Upgrade error but got " <> show e diff --git a/sdk/daml-script/test/daml/upgrades/Fetch.daml b/sdk/daml-script/test/daml/upgrades/Fetch.daml index 402b516cc9fb..66463e732864 100644 --- a/sdk/daml-script/test/daml/upgrades/Fetch.daml +++ b/sdk/daml-script/test/daml/upgrades/Fetch.daml @@ -84,7 +84,7 @@ fetchDowngradedSome = test $ do eV1Name <- a `tryExerciseV1Util` V1.DoFetch with cid = v1Cid case eV1Name of - Left (DevError Upgrade msg) + Left (UpgradeError msg) | "An optional contract field with a value of Some may not be dropped during downgrading" `isInfixOf` msg -> pure () res -> assertFail $ "Expected DevError Upgrade, got " <> show res diff --git a/sdk/daml-script/test/daml/upgrades/FromInterface.daml b/sdk/daml-script/test/daml/upgrades/FromInterface.daml index 75ceecb38d1d..79fc258422d3 100644 --- a/sdk/daml-script/test/daml/upgrades/FromInterface.daml +++ b/sdk/daml-script/test/daml/upgrades/FromInterface.daml @@ -147,5 +147,5 @@ fromInterfaceInvalidDowngrade = test $ do res <- a `trySubmit` createAndExerciseCmd (TestHelper a) InvalidDowngrade case res of Right _ -> fail "Expected failure but got success" - Left (DevError Upgrade msg) | "field with a value of Some may not be dropped" `isInfixOf` msg -> pure () + Left (UpgradeError msg) | "field with a value of Some may not be dropped" `isInfixOf` msg -> pure () Left e -> fail $ "Expected Upgrade error but got " <> show e diff --git a/sdk/daml-script/test/daml/upgrades/InterfaceViews.daml b/sdk/daml-script/test/daml/upgrades/InterfaceViews.daml index aa848d7e4b5b..a12629117c2e 100644 --- a/sdk/daml-script/test/daml/upgrades/InterfaceViews.daml +++ b/sdk/daml-script/test/daml/upgrades/InterfaceViews.daml @@ -164,7 +164,7 @@ exerciseCommandShouldFail = test $ do (alice, icid) <- setupAliceAndInterface res <- alice `trySubmit` exerciseCmd icid GetVersion case res of - Left (DevError Upgrade msg) | "View mismatch" `isInfixOf` msg -> pure () + Left (UpgradeError msg) | "View mismatch" `isInfixOf` msg -> pure () _ -> assertFail ("Expected fetchFromInterface to fail, got " <> show res) exerciseInChoiceBodyShouldFail : Test @@ -172,7 +172,7 @@ exerciseInChoiceBodyShouldFail = test $ do (alice, icid) <- setupAliceAndInterface res <- alice `trySubmit` createAndExerciseCmd (Caller with party = alice) (CallInterface with icid = icid) case res of - Left (DevError Upgrade msg) | "View mismatch" `isInfixOf` msg -> pure () + Left (UpgradeError msg) | "View mismatch" `isInfixOf` msg -> pure () _ -> assertFail ("Expected fetchFromInterface to fail, got " <> show res) fetchFromInterfaceShouldFail : Test @@ -180,7 +180,7 @@ fetchFromInterfaceShouldFail = test $ do (alice, icid) <- setupAliceAndInterface res <- alice `trySubmit` createAndExerciseExactCmd (V2.FITemplate with party = alice) (V2.FetchFromInterface with icid = icid) case res of - Left (DevError Upgrade msg) | "View mismatch" `isInfixOf` msg -> pure () + Left (UpgradeError msg) | "View mismatch" `isInfixOf` msg -> pure () _ -> assertFail ("Expected fetchFromInterface to fail, got " <> show res) queryInterfaceContractIdInView : Test diff --git a/sdk/daml-script/test/daml/upgrades/SignatoryObserverChanges.daml b/sdk/daml-script/test/daml/upgrades/SignatoryObserverChanges.daml index 312f44d1fcb3..63cf44787025 100644 --- a/sdk/daml-script/test/daml/upgrades/SignatoryObserverChanges.daml +++ b/sdk/daml-script/test/daml/upgrades/SignatoryObserverChanges.daml @@ -116,7 +116,7 @@ signatoryObserverUpgrade shouldSucceed sigF obsF exerciseChoice = test $ do res <- trySubmitMulti [alice, bob, charlie] [] $ exerciseChoice cid case (res, shouldSucceed) of (Right _, True) -> pure () - (Left (DevError Upgrade msg), False) + (Left (UpgradeError msg), False) | "Verify that neither the signatories, nor the observers, nor the contract key, nor the key's maintainers have changed" `isInfixOf` msg -> pure () _ -> assertFail $ "Expected " <> (if shouldSucceed then "success" else "Upgrade error") <> " but got " <> show res diff --git a/sdk/daml-script/test/daml/upgrades/VariantChanges.daml b/sdk/daml-script/test/daml/upgrades/VariantChanges.daml index 4c096c958506..7b443d387a4e 100644 --- a/sdk/daml-script/test/daml/upgrades/VariantChanges.daml +++ b/sdk/daml-script/test/daml/upgrades/VariantChanges.daml @@ -60,7 +60,7 @@ templateInvalidChange shouldSucceed makeV1Contract v2Choice = test $ do case (res, shouldSucceed) of (Right "V1", True) -> pure () (Right "V2", True) -> pure () - (Left (DevError Upgrade _), False) -> pure () + (Left (UpgradeError _), False) -> pure () (Left (WronglyTypedContract {}), False) -> pure () (Left (UnknownError msg), False) | "An error occurred." `isInfixOf` msg -> pure () -- IDE Ledger doesn't apply obfuscation, instead the lookup error is wrapped in SCrash