OZContractErrorCodes

public enum OZContractErrorCodes

Contract-level error codes from the OpenZeppelin smart account, WebAuthn verifier, and policy contracts.

When a contract rejects a simulated call, the kit’s SmartAccountTransactionException.SimulationFailed carries the contract error the simulation reports as reportedContractError, taken from the host error or, when the host masks it, from the diagnostic events; decodeFromSimulationFailure(_:) names it. The code also appears in the exception’s message (for example Error(Contract, #3016)), where decodeFromMessage(_:) finds it. decode(_:) resolves a raw code.

The named constants below cover the smart account contract’s own error enum — the codes a caller is most likely to branch on. decode(_:) resolves any known code (smart account, WebAuthn, or a policy contract) into its contract and variant name.

  • The referenced context rule does not exist on the account.

    Declaration

    Swift

    public static let contextRuleNotFound: Int
  • The invocation context could not be validated against the account’s context rules.

    Declaration

    Swift

    public static let unvalidatedContext: Int
  • An external signer’s verifier contract rejected the signature.

    Declaration

    Swift

    public static let externalVerificationFailed: Int
  • A context rule must have at least one signer or one policy.

    Declaration

    Swift

    public static let noSignersAndPolicies: Int
  • The context rule’s valid_until ledger has already passed.

    Declaration

    Swift

    public static let pastValidUntil: Int
  • The referenced signer is not present on the context rule.

    Declaration

    Swift

    public static let signerNotFound: Int
  • The signer is already present on the context rule.

    Declaration

    Swift

    public static let duplicateSigner: Int
  • The referenced policy is not installed on the context rule.

    Declaration

    Swift

    public static let policyNotFound: Int
  • The policy is already installed on the context rule.

    Declaration

    Swift

    public static let duplicatePolicy: Int
  • The context rule exceeds the maximum number of signers.

    Declaration

    Swift

    public static let tooManySigners: Int
  • The context rule exceeds the maximum number of policies.

    Declaration

    Swift

    public static let tooManyPolicies: Int
  • Integer arithmetic overflow occurred in the contract.

    Declaration

    Swift

    public static let mathOverflow: Int
  • The key_data field on a signer exceeds the maximum allowed size.

    Declaration

    Swift

    public static let keyDataTooLarge: Int
  • The number of context rule IDs in the auth payload does not match the expected count.

    Declaration

    Swift

    public static let contextRuleIdsLengthMismatch: Int
  • A name field (e.g. context rule name) exceeds the maximum allowed length.

    Declaration

    Swift

    public static let nameTooLong: Int
  • The signer is not authorized to sign the given context rule.

    Declaration

    Swift

    public static let unauthorizedSigner: Int
  • A Delegated signer’s address is the contract of a context being authorized.

    Declaration

    Swift

    public static let delegatedSignerIsContextContract: Int
  • A Delegated signer’s address is the smart account itself.

    Declaration

    Swift

    public static let selfDelegatedSigner: Int
  • Decodes a raw contract error code into the OZ contract and variant name that defined it, or nil if code is not a known OZ smart-account contract error.

    Declaration

    Swift

    public static func decode(_ code: Int) -> OZContractError?

    Parameters

    code

    The numeric contract error code to decode.

    Return Value

    The decoded OZContractError, or nil for unknown codes.

  • Decodes the contract error a simulation failure reports.

    Reads only failure.reportedContractError; the message is not searched, so an unknown reported code gives nil even when the message names a known one. The selection behind the reported code is a heuristic, and a code of a contract outside the OpenZeppelin suite can collide with a known code; see ReportedContractError.

    Declaration

    Swift

    public static func decodeFromSimulationFailure(
        _ failure: SmartAccountTransactionException.SimulationFailed
    ) -> OZContractError?

    Parameters

    failure

    The simulation failure thrown by the kit.

    Return Value

    The decoded OZContractError, or nil when the failure reports no code or an unknown one.

  • Extracts and decodes the first known contract error code from an error message.

    Contract failures appear as Error(Contract, #NNNN) inside simulation and submission error strings (typically the message of a thrown SmartAccountTransactionException, including the contract error suffix the kit appends when the host error masks the code). This scans the message for such markers and returns the first one whose code is a known OZ smart-account contract error, or nil when the message is nil, carries no marker, or carries only unknown codes.

    Declaration

    Swift

    public static func decodeFromMessage(_ message: String?) -> OZContractError?

    Parameters

    message

    The error message to scan.

    Return Value

    The decoded OZContractError, or nil when no known code is found.