Improve SubmitError show instance (#17216)

This commit is contained in:
Carl Pulley 2023-08-10 12:05:07 +01:00 committed by GitHub
parent d8a409f816
commit 38085a8787
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import Daml.Script.Questions.Util
import DA.NonEmpty import DA.NonEmpty
import DA.Text import DA.Text
import DA.Foldable (foldMap) import DA.Foldable (foldMap)
import DA.Exception
-- | Errors that will be promoted to SubmitError once stable -- | Errors that will be promoted to SubmitError once stable
data DevErrorType data DevErrorType
@ -121,34 +122,38 @@ data SubmitError
-- TODO: Should we expose this at all? -- TODO: Should we expose this at all?
TruncatedError with TruncatedError with
truncatedErrorType : Text 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 truncatedErrorMessage : Text
-- TODO[SW]: Add more detail here instance Show AnyContractKey where
show (AnyContractKey _ templateTypeRep) = show templateTypeRep
instance Show SubmitError where instance Show SubmitError where
show err = case err of show err = case err of
ContractNotFound { unknownContractIds, additionalDebuggingInfo } -> ContractNotFound { unknownContractIds, additionalDebuggingInfo } ->
"Could not find contract with ID(s) " <> intercalate ", " (toList unknownContractIds) <> "." "Could not find contract with ID(s) " <> intercalate ", " (toList unknownContractIds) <> "."
<> foldMap (\info -> " Additional debugging info: " <> show info) additionalDebuggingInfo <> 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 AuthorizationError errMessage -> "Authorization failure: " <> errMessage
DisclosedContractKeyHashingError contractId _ _ -> "Disclosed contract with ID " <> show contractId.contractId <> " used incorrect payload" DisclosedContractKeyHashingError contractId contractKey contractKeyHash ->
DuplicateContractKey {} -> "Attempted to create a contract with a contract key that is already in use" "Disclosed contract with ID " <> show contractId <> " used incorrect payload - contract key: " <> show contractKey <> "; and contract key hash: " <> contractKeyHash
InconsistentContractKey {} -> "Inconsistent contract key between daml and ledger" DuplicateContractKey contractKey -> "Attempted to create a contract with a contract key that is already in use - contract key: " <> show contractKey
UnhandledException {} -> "An Exception was thrown and not caught" 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 UserError errMessage -> "User Error: " <> errMessage
TemplatePreconditionViolated {} -> "Template precondition was violated" TemplatePreconditionViolated {} -> "Template precondition was violated"
CreateEmptyContractKeyMaintainers {} -> "Attempted to create a contract with empty key maintainers" CreateEmptyContractKeyMaintainers _ -> "Attempted to create a contract with empty key maintainers"
FetchEmptyContractKeyMaintainers {} -> "Attempted to fetch a contract with empty key maintainers" FetchEmptyContractKeyMaintainers contractKey -> "Attempted to fetch a contract with empty key maintainers - contract key: " <> show contractKey
WronglyTypedContract _ expected actual -> WronglyTypedContract contractId expected actual ->
"Excepted contract to be a \"" <> templateTypeRepToText expected <> "\" but it was actually a \"" <> templateTypeRepToText actual <> "\"" "Excepted contract ID " <> show contractId <> " to be a \"" <> templateTypeRepToText expected <> "\" but it was actually a \"" <> templateTypeRepToText actual <> "\""
ContractDoesNotImplementInterface _ t i -> ContractDoesNotImplementInterface contractId templateId interfaceId ->
"\"" <> templateTypeRepToText t <> "\" does not implement interface \"" <> templateTypeRepToText i <> "\"" "\"" <> templateTypeRepToText templateId <> "\" does not implement interface \"" <> templateTypeRepToText interfaceId <> "\" for contract ID: " <> show contractId
ContractDoesNotImplementRequiringInterface _ t required requiring -> ContractDoesNotImplementRequiringInterface contractId templateId required requiring ->
"\"" <> templateTypeRepToText t <> "\" does not implement interface \"" <> templateTypeRepToText required <> "\" as required by \"" <> templateTypeRepToText requiring <> "\"" "\"" <> templateTypeRepToText templateId <> "\" does not implement interface \"" <> templateTypeRepToText required <> "\" as required by \"" <> templateTypeRepToText requiring <> "\" for contract ID: " <> show contractId
NonComparableValues {} -> "Failed to compare values" NonComparableValues {} -> "Failed to compare values"
ContractIdInContractKey {} -> "Illegal contract ID in contract key" 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 <> "\"" DevError ty msg -> "DevError of type " <> show ty <> " and message \"" <> msg <> "\""
UnknownError msg -> "Unknown error: " <> msg UnknownError msg -> "Unknown error: " <> msg
TruncatedError ty msg -> "TruncatedError of type " <> ty <> " and message \"" <> msg <> "\"" TruncatedError ty msg -> "TruncatedError of type " <> ty <> " and message \"" <> msg <> "\""