From 38085a8787c1703fa597e2eb0aa8262b60b902c2 Mon Sep 17 00:00:00 2001 From: Carl Pulley <106966370+carlpulley-da@users.noreply.github.com> Date: Thu, 10 Aug 2023 12:05:07 +0100 Subject: [PATCH] Improve SubmitError show instance (#17216) --- .../Daml/Script/Questions/Submit/Error.daml | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/daml-script/daml3/Daml/Script/Questions/Submit/Error.daml b/daml-script/daml3/Daml/Script/Questions/Submit/Error.daml index 0f3826dddbb..63c47cadedb 100644 --- a/daml-script/daml3/Daml/Script/Questions/Submit/Error.daml +++ b/daml-script/daml3/Daml/Script/Questions/Submit/Error.daml @@ -12,6 +12,7 @@ import Daml.Script.Questions.Util import DA.NonEmpty import DA.Text import DA.Foldable (foldMap) +import DA.Exception -- | Errors that will be promoted to SubmitError once stable data DevErrorType @@ -121,34 +122,38 @@ data SubmitError -- TODO: Should we expose this at all? TruncatedError with truncatedErrorType : Text - -- ^ One of the contructor names of SubmitFailure except DevError, UnknownError, TruncatedError + -- ^ One of the constructor names of SubmitFailure except DevError, UnknownError, TruncatedError truncatedErrorMessage : Text --- TODO[SW]: Add more detail here +instance Show AnyContractKey where + show (AnyContractKey _ templateTypeRep) = show templateTypeRep + instance Show SubmitError where show err = case err of ContractNotFound { unknownContractIds, additionalDebuggingInfo } -> "Could not find contract with ID(s) " <> intercalate ", " (toList unknownContractIds) <> "." <> foldMap (\info -> " Additional debugging info: " <> show info) additionalDebuggingInfo - ContractKeyNotFound {} -> "Could not find contract with given key" + ContractKeyNotFound contractKey -> "Could not find contract with given key: " <> show contractKey AuthorizationError errMessage -> "Authorization failure: " <> errMessage - DisclosedContractKeyHashingError contractId _ _ -> "Disclosed contract with ID " <> show contractId.contractId <> " used incorrect payload" - DuplicateContractKey {} -> "Attempted to create a contract with a contract key that is already in use" - InconsistentContractKey {} -> "Inconsistent contract key between daml and ledger" - UnhandledException {} -> "An Exception was thrown and not caught" + DisclosedContractKeyHashingError contractId contractKey contractKeyHash -> + "Disclosed contract with ID " <> show contractId <> " used incorrect payload - contract key: " <> show contractKey <> "; and contract key hash: " <> contractKeyHash + DuplicateContractKey contractKey -> "Attempted to create a contract with a contract key that is already in use - contract key: " <> show contractKey + InconsistentContractKey contractKey -> "Inconsistent contract key between daml and ledger - contract key: " <> show contractKey + UnhandledException None -> "An Exception was thrown and not caught" + UnhandledException (Some exn) -> "An Exception was thrown and not caught - message: " <> (message exn) UserError errMessage -> "User Error: " <> errMessage TemplatePreconditionViolated {} -> "Template precondition was violated" - CreateEmptyContractKeyMaintainers {} -> "Attempted to create a contract with empty key maintainers" - FetchEmptyContractKeyMaintainers {} -> "Attempted to fetch a contract with empty key maintainers" - WronglyTypedContract _ expected actual -> - "Excepted contract to be a \"" <> templateTypeRepToText expected <> "\" but it was actually a \"" <> templateTypeRepToText actual <> "\"" - ContractDoesNotImplementInterface _ t i -> - "\"" <> templateTypeRepToText t <> "\" does not implement interface \"" <> templateTypeRepToText i <> "\"" - ContractDoesNotImplementRequiringInterface _ t required requiring -> - "\"" <> templateTypeRepToText t <> "\" does not implement interface \"" <> templateTypeRepToText required <> "\" as required by \"" <> templateTypeRepToText requiring <> "\"" + CreateEmptyContractKeyMaintainers _ -> "Attempted to create a contract with empty key maintainers" + FetchEmptyContractKeyMaintainers contractKey -> "Attempted to fetch a contract with empty key maintainers - contract key: " <> show contractKey + WronglyTypedContract contractId expected actual -> + "Excepted contract ID " <> show contractId <> " to be a \"" <> templateTypeRepToText expected <> "\" but it was actually a \"" <> templateTypeRepToText actual <> "\"" + ContractDoesNotImplementInterface contractId templateId interfaceId -> + "\"" <> templateTypeRepToText templateId <> "\" does not implement interface \"" <> templateTypeRepToText interfaceId <> "\" for contract ID: " <> show contractId + ContractDoesNotImplementRequiringInterface contractId templateId required requiring -> + "\"" <> templateTypeRepToText templateId <> "\" does not implement interface \"" <> templateTypeRepToText required <> "\" as required by \"" <> templateTypeRepToText requiring <> "\" for contract ID: " <> show contractId NonComparableValues {} -> "Failed to compare values" ContractIdInContractKey {} -> "Illegal contract ID in contract key" - ContractIdComparability {} -> "Attempted to compare local and global contract IDs of the same contract" + ContractIdComparability contractId -> "Attempted to compare local and global contract IDs of the same contract - contract ID: " <> contractId 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 <> "\""