sui_sdk_types/
execution_status.rs

1use super::Address;
2use super::Digest;
3use super::Identifier;
4use super::ObjectId;
5
6/// The status of an executed Transaction
7///
8/// # BCS
9///
10/// The BCS serialized form for this type is defined by the following ABNF:
11///
12/// ```text
13/// execution-status = success / failure
14/// success = %x00
15/// failure = %x01 execution-error (option u64)
16/// ```
17#[derive(Eq, PartialEq, Clone, Debug)]
18#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
19pub enum ExecutionStatus {
20    /// The Transaction successfully executed.
21    Success,
22
23    /// The Transaction didn't execute successfully.
24    ///
25    /// Failed transactions are still committed to the blockchain but any intended effects are
26    /// rolled back to prior to this transaction executing with the caveat that gas objects are
27    /// still smashed and gas usage is still charged.
28    Failure {
29        /// The error encountered during execution.
30        error: ExecutionError,
31        /// The command, if any, during which the error occurred.
32        #[cfg_attr(feature = "proptest", map(|x: Option<u16>| x.map(Into::into)))]
33        command: Option<u64>,
34    },
35}
36
37/// An error that can occur during the execution of a transaction
38///
39/// # BCS
40///
41/// The BCS serialized form for this type is defined by the following ABNF:
42///
43/// ```text
44/// execution-error =  insufficient-gas
45///                 =/ invalid-gas-object
46///                 =/ invariant-violation
47///                 =/ feature-not-yet-supported
48///                 =/ object-too-big
49///                 =/ package-too-big
50///                 =/ circular-object-ownership
51///                 =/ insufficient-coin-balance
52///                 =/ coin-balance-overflow
53///                 =/ publish-error-non-zero-address
54///                 =/ sui-move-verification-error
55///                 =/ move-primitive-runtime-error
56///                 =/ move-abort
57///                 =/ vm-verification-or-deserialization-error
58///                 =/ vm-invariant-violation
59///                 =/ function-not-found
60///                 =/ arity-mismatch
61///                 =/ type-arity-mismatch
62///                 =/ non-entry-function-invoked
63///                 =/ command-argument-error
64///                 =/ type-argument-error
65///                 =/ unused-value-without-drop
66///                 =/ invalid-public-function-return-type
67///                 =/ invalid-transfer-object
68///                 =/ effects-too-large
69///                 =/ publish-upgrade-missing-dependency
70///                 =/ publish-upgrade-dependency-downgrade
71///                 =/ package-upgrade-error
72///                 =/ written-objects-too-large
73///                 =/ certificate-denied
74///                 =/ sui-move-verification-timedout
75///                 =/ shared-object-operation-not-allowed
76///                 =/ input-object-deleted
77///                 =/ execution-canceled-due-to-shared-object-congestion
78///                 =/ address-denied-for-coin
79///                 =/ coin-type-global-pause
80///                 =/ execution-canceled-due-to-randomness-unavailable
81///
82/// insufficient-gas                                    = %x00
83/// invalid-gas-object                                  = %x01
84/// invariant-violation                                 = %x02
85/// feature-not-yet-supported                           = %x03
86/// object-too-big                                      = %x04 u64 u64
87/// package-too-big                                     = %x05 u64 u64
88/// circular-object-ownership                           = %x06 object-id
89/// insufficient-coin-balance                           = %x07
90/// coin-balance-overflow                               = %x08
91/// publish-error-non-zero-address                      = %x09
92/// sui-move-verification-error                         = %x0a
93/// move-primitive-runtime-error                        = %x0b (option move-location)
94/// move-abort                                          = %x0c move-location u64
95/// vm-verification-or-deserialization-error            = %x0d
96/// vm-invariant-violation                              = %x0e
97/// function-not-found                                  = %x0f
98/// arity-mismatch                                      = %x10
99/// type-arity-mismatch                                 = %x11
100/// non-entry-function-invoked                          = %x12
101/// command-argument-error                              = %x13 u16 command-argument-error
102/// type-argument-error                                 = %x14 u16 type-argument-error
103/// unused-value-without-drop                           = %x15 u16 u16
104/// invalid-public-function-return-type                 = %x16 u16
105/// invalid-transfer-object                             = %x17
106/// effects-too-large                                   = %x18 u64 u64
107/// publish-upgrade-missing-dependency                  = %x19
108/// publish-upgrade-dependency-downgrade                = %x1a
109/// package-upgrade-error                               = %x1b package-upgrade-error
110/// written-objects-too-large                           = %x1c u64 u64
111/// certificate-denied                                  = %x1d
112/// sui-move-verification-timedout                      = %x1e
113/// shared-object-operation-not-allowed                 = %x1f
114/// input-object-deleted                                = %x20
115/// execution-canceled-due-to-shared-object-congestion = %x21 (vector object-id)
116/// address-denied-for-coin                             = %x22 address string
117/// coin-type-global-pause                              = %x23 string
118/// execution-canceled-due-to-randomness-unavailable   = %x24
119/// ```
120#[derive(Eq, PartialEq, Clone, Debug)]
121#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
122pub enum ExecutionError {
123    //
124    // General transaction errors
125    //
126    /// Insufficient Gas
127    InsufficientGas,
128    /// Invalid Gas Object.
129    InvalidGasObject,
130    /// Invariant Violation
131    InvariantViolation,
132    /// Attempted to used feature that is not supported yet
133    FeatureNotYetSupported,
134    /// Move object is larger than the maximum allowed size
135    ObjectTooBig {
136        object_size: u64,
137        max_object_size: u64,
138    },
139    /// Package is larger than the maximum allowed size
140    PackageTooBig {
141        object_size: u64,
142        max_object_size: u64,
143    },
144    /// Circular Object Ownership
145    CircularObjectOwnership { object: ObjectId },
146
147    //
148    // Coin errors
149    //
150    /// Insufficient coin balance for requested operation
151    InsufficientCoinBalance,
152    /// Coin balance overflowed an u64
153    CoinBalanceOverflow,
154
155    //
156    // Publish/Upgrade errors
157    //
158    /// Publish Error, Non-zero Address.
159    /// The modules in the package must have their self-addresses set to zero.
160    PublishErrorNonZeroAddress,
161
162    /// Sui Move Bytecode Verification Error.
163    SuiMoveVerificationError,
164
165    //
166    // MoveVm Errors
167    //
168    /// Error from a non-abort instruction.
169    /// Possible causes:
170    ///     Arithmetic error, stack overflow, max value depth, etc."
171    MovePrimitiveRuntimeError { location: Option<MoveLocation> },
172    /// Move runtime abort
173    MoveAbort { location: MoveLocation, code: u64 },
174    /// Bytecode verification error.
175    VmVerificationOrDeserializationError,
176    /// MoveVm invariant violation
177    VmInvariantViolation,
178
179    //
180    // Programmable Transaction Errors
181    //
182    /// Function not found
183    FunctionNotFound,
184    /// Arity mismatch for Move function.
185    /// The number of arguments does not match the number of parameters
186    ArityMismatch,
187    /// Type arity mismatch for Move function.
188    /// Mismatch between the number of actual versus expected type arguments.
189    TypeArityMismatch,
190    /// Non Entry Function Invoked. Move Call must start with an entry function.
191    NonEntryFunctionInvoked,
192    /// Invalid command argument
193    CommandArgumentError {
194        argument: u16,
195        kind: CommandArgumentError,
196    },
197    /// Type argument error
198    TypeArgumentError {
199        /// Index of the problematic type argument
200        type_argument: u16,
201        kind: TypeArgumentError,
202    },
203    /// Unused result without the drop ability.
204    UnusedValueWithoutDrop { result: u16, subresult: u16 },
205    /// Invalid public Move function signature.
206    /// Unsupported return type for return value
207    InvalidPublicFunctionReturnType { index: u16 },
208    /// Invalid Transfer Object, object does not have public transfer.
209    InvalidTransferObject,
210
211    //
212    // Post-execution errors
213    //
214    /// Effects from the transaction are too large
215    EffectsTooLarge { current_size: u64, max_size: u64 },
216
217    /// Publish or Upgrade is missing dependency
218    PublishUpgradeMissingDependency,
219
220    /// Publish or Upgrade dependency downgrade.
221    ///
222    /// Indirect (transitive) dependency of published or upgraded package has been assigned an
223    /// on-chain version that is less than the version required by one of the package's
224    /// transitive dependencies.
225    PublishUpgradeDependencyDowngrade,
226
227    /// Invalid package upgrade
228    PackageUpgradeError { kind: PackageUpgradeError },
229
230    /// Indicates the transaction tried to write objects too large to storage
231    WrittenObjectsTooLarge {
232        object_size: u64,
233        max_object_size: u64,
234    },
235
236    /// Certificate is on the deny list
237    CertificateDenied,
238
239    /// Sui Move Bytecode verification timed out.
240    SuiMoveVerificationTimedout,
241
242    /// The requested shared object operation is not allowed
243    SharedObjectOperationNotAllowed,
244
245    /// Requested shared object has been deleted
246    InputObjectDeleted,
247
248    /// Certificate is canceled due to congestion on shared objects
249    ExecutionCanceledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },
250
251    /// Address is denied for this coin type
252    AddressDeniedForCoin { address: Address, coin_type: String },
253
254    /// Coin type is globally paused for use
255    CoinTypeGlobalPause { coin_type: String },
256
257    /// Certificate is canceled because randomness could not be generated this epoch
258    ExecutionCanceledDueToRandomnessUnavailable,
259}
260
261/// Location in move bytecode where an error occurred
262///
263/// # BCS
264///
265/// The BCS serialized form for this type is defined by the following ABNF:
266///
267/// ```text
268/// move-location = object-id identifier u16 u16 (option identifier)
269/// ```
270#[derive(Eq, PartialEq, Clone, Debug)]
271#[cfg_attr(
272    feature = "serde",
273    derive(serde_derive::Serialize, serde_derive::Deserialize)
274)]
275#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
276pub struct MoveLocation {
277    /// The package id
278    pub package: ObjectId,
279
280    /// The module name
281    pub module: Identifier,
282
283    /// The function index
284    pub function: u16,
285
286    /// Index into the code stream for a jump. The offset is relative to the beginning of
287    /// the instruction stream.
288    pub instruction: u16,
289
290    /// The name of the function if available
291    pub function_name: Option<Identifier>,
292}
293
294/// An error with an argument to a command
295///
296/// # BCS
297///
298/// The BCS serialized form for this type is defined by the following ABNF:
299///
300/// ```text
301/// command-argument-error =  type-mismatch
302///                        =/ invalid-bcs-bytes
303///                        =/ invalid-usage-of-pure-argument
304///                        =/ invalid-argument-to-private-entry-function
305///                        =/ index-out-of-bounds
306///                        =/ secondary-index-out-of-bound
307///                        =/ invalid-result-arity
308///                        =/ invalid-gas-coin-usage
309///                        =/ invalid-value-usage
310///                        =/ invalid-object-by-value
311///                        =/ invalid-object-by-mut-ref
312///                        =/ shared-object-operation-not-allowed
313///
314/// type-mismatch                               = %x00
315/// invalid-bcs-bytes                           = %x01
316/// invalid-usage-of-pure-argument              = %x02
317/// invalid-argument-to-private-entry-function  = %x03
318/// index-out-of-bounds                         = %x04 u16
319/// secondary-index-out-of-bound                = %x05 u16 u16
320/// invalid-result-arity                        = %x06 u16
321/// invalid-gas-coin-usage                      = %x07
322/// invalid-value-usage                         = %x08
323/// invalid-object-by-value                     = %x09
324/// invalid-object-by-mut-ref                   = %x0a
325/// shared-object-operation-not-allowed         = %x0b
326/// ```
327#[derive(Eq, PartialEq, Clone, Debug)]
328#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
329pub enum CommandArgumentError {
330    /// The type of the value does not match the expected type
331    TypeMismatch,
332
333    /// The argument cannot be deserialized into a value of the specified type
334    InvalidBcsBytes,
335
336    /// The argument cannot be instantiated from raw bytes
337    InvalidUsageOfPureArgument,
338
339    /// Invalid argument to private entry function.
340    /// Private entry functions cannot take arguments from other Move functions.
341    InvalidArgumentToPrivateEntryFunction,
342
343    /// Out of bounds access to input or results
344    IndexOutOfBounds { index: u16 },
345
346    /// Out of bounds access to subresult
347    SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
348
349    /// Invalid usage of result.
350    /// Expected a single result but found either no return value or multiple.
351    InvalidResultArity { result: u16 },
352
353    /// Invalid usage of Gas coin.
354    /// The Gas coin can only be used by-value with a TransferObjects command.
355    InvalidGasCoinUsage,
356
357    /// Invalid usage of move value.
358    //     Mutably borrowed values require unique usage.
359    //     Immutably borrowed values cannot be taken or borrowed mutably.
360    //     Taken values cannot be used again.
361    InvalidValueUsage,
362
363    /// Immutable objects cannot be passed by-value.
364    InvalidObjectByValue,
365
366    /// Immutable objects cannot be passed by mutable reference, &mut.
367    InvalidObjectByMutRef,
368
369    /// Shared object operations such a wrapping, freezing, or converting to owned are not
370    /// allowed.
371    SharedObjectOperationNotAllowed,
372}
373
374/// An error with a upgrading a package
375///
376/// # BCS
377///
378/// The BCS serialized form for this type is defined by the following ABNF:
379///
380/// ```text
381/// package-upgrade-error = unable-to-fetch-package /
382///                         not-a-package           /
383///                         incompatible-upgrade    /
384///                         digest-does-not-match   /
385///                         unknown-upgrade-policy  /
386///                         package-id-does-not-match
387///
388/// unable-to-fetch-package     = %x00 object-id
389/// not-a-package               = %x01 object-id
390/// incompatible-upgrade        = %x02
391/// digest-does-not-match       = %x03 digest
392/// unknown-upgrade-policy      = %x04 u8
393/// package-id-does-not-match   = %x05 object-id object-id
394/// ```
395#[derive(Eq, PartialEq, Clone, Debug)]
396#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
397pub enum PackageUpgradeError {
398    /// Unable to fetch package
399    UnableToFetchPackage { package_id: ObjectId },
400
401    /// Object is not a package
402    NotAPackage { object_id: ObjectId },
403
404    /// Package upgrade is incompatible with previous version
405    IncompatibleUpgrade,
406
407    /// Digest in upgrade ticket and computed digest differ
408    DigestDoesNotMatch { digest: Digest },
409
410    /// Upgrade policy is not valid
411    UnknownUpgradePolicy { policy: u8 },
412
413    /// PackageId does not matach PackageId in upgrade ticket
414    PackageIdDoesNotMatch {
415        package_id: ObjectId,
416        ticket_id: ObjectId,
417    },
418}
419
420/// An error with a type argument
421///
422/// # BCS
423///
424/// The BCS serialized form for this type is defined by the following ABNF:
425///
426/// ```text
427/// type-argument-error = type-not-found / constraint-not-satisfied
428/// type-not-found = %x00
429/// constraint-not-satisfied = %x01
430/// ```
431#[derive(Eq, PartialEq, Clone, Copy, Debug)]
432#[cfg_attr(
433    feature = "serde",
434    derive(serde_derive::Serialize, serde_derive::Deserialize),
435    serde(rename_all = "snake_case")
436)]
437#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
438pub enum TypeArgumentError {
439    /// A type was not found in the module specified
440    TypeNotFound,
441
442    /// A type provided did not match the specified constraint
443    ConstraintNotSatisfied,
444}
445
446#[cfg(feature = "serde")]
447#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
448mod serialization {
449    use super::*;
450
451    use serde::Deserialize;
452    use serde::Deserializer;
453    use serde::Serialize;
454    use serde::Serializer;
455
456    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
457    #[serde(rename = "ExecutionStatus")]
458    struct ReadableExecutionStatus {
459        success: bool,
460        #[serde(skip_serializing_if = "Option::is_none")]
461        status: Option<FailureStatus>,
462    }
463
464    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
465    struct FailureStatus {
466        error: ExecutionError,
467        #[serde(skip_serializing_if = "Option::is_none")]
468        command: Option<u16>,
469    }
470
471    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
472    enum BinaryExecutionStatus {
473        Success,
474        Failure {
475            error: ExecutionError,
476            command: Option<u64>,
477        },
478    }
479
480    impl Serialize for ExecutionStatus {
481        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
482        where
483            S: Serializer,
484        {
485            if serializer.is_human_readable() {
486                let readable = match self.clone() {
487                    ExecutionStatus::Success => ReadableExecutionStatus {
488                        success: true,
489                        status: None,
490                    },
491                    ExecutionStatus::Failure { error, command } => ReadableExecutionStatus {
492                        success: false,
493                        status: Some(FailureStatus {
494                            error,
495                            command: command.map(|c| c as u16),
496                        }),
497                    },
498                };
499                readable.serialize(serializer)
500            } else {
501                let binary = match self.clone() {
502                    ExecutionStatus::Success => BinaryExecutionStatus::Success,
503                    ExecutionStatus::Failure { error, command } => {
504                        BinaryExecutionStatus::Failure { error, command }
505                    }
506                };
507                binary.serialize(serializer)
508            }
509        }
510    }
511
512    impl<'de> Deserialize<'de> for ExecutionStatus {
513        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
514        where
515            D: Deserializer<'de>,
516        {
517            if deserializer.is_human_readable() {
518                let ReadableExecutionStatus { success, status } =
519                    Deserialize::deserialize(deserializer)?;
520                match (success, status) {
521                    (true, None) => Ok(ExecutionStatus::Success),
522                    (false, Some(FailureStatus { error, command })) => {
523                        Ok(ExecutionStatus::Failure {
524                            error,
525                            command: command.map(Into::into),
526                        })
527                    }
528                    // invalid cases
529                    (true, Some(_)) | (false, None) => {
530                        Err(serde::de::Error::custom("invalid execution status"))
531                    }
532                }
533            } else {
534                BinaryExecutionStatus::deserialize(deserializer).map(|readable| match readable {
535                    BinaryExecutionStatus::Success => Self::Success,
536                    BinaryExecutionStatus::Failure { error, command } => {
537                        Self::Failure { error, command }
538                    }
539                })
540            }
541        }
542    }
543
544    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
545    #[serde(tag = "error", rename_all = "snake_case")]
546    enum ReadableExecutionError {
547        InsufficientGas,
548        InvalidGasObject,
549        InvariantViolation,
550        FeatureNotYetSupported,
551        ObjectTooBig {
552            #[serde(with = "crate::_serde::ReadableDisplay")]
553            object_size: u64,
554            #[serde(with = "crate::_serde::ReadableDisplay")]
555            max_object_size: u64,
556        },
557        PackageTooBig {
558            #[serde(with = "crate::_serde::ReadableDisplay")]
559            object_size: u64,
560            #[serde(with = "crate::_serde::ReadableDisplay")]
561            max_object_size: u64,
562        },
563        CircularObjectOwnership {
564            object: ObjectId,
565        },
566        InsufficientCoinBalance,
567        CoinBalanceOverflow,
568        PublishErrorNonZeroAddress,
569        SuiMoveVerificationError,
570        MovePrimitiveRuntimeError {
571            location: Option<MoveLocation>,
572        },
573        MoveAbort {
574            location: MoveLocation,
575            #[serde(with = "crate::_serde::ReadableDisplay")]
576            code: u64,
577        },
578        VmVerificationOrDeserializationError,
579        VmInvariantViolation,
580        FunctionNotFound,
581        ArityMismatch,
582        TypeArityMismatch,
583        NonEntryFunctionInvoked,
584        CommandArgumentError {
585            argument: u16,
586            kind: CommandArgumentError,
587        },
588        TypeArgumentError {
589            type_argument: u16,
590            kind: TypeArgumentError,
591        },
592        UnusedValueWithoutDrop {
593            result: u16,
594            subresult: u16,
595        },
596        InvalidPublicFunctionReturnType {
597            index: u16,
598        },
599        InvalidTransferObject,
600        EffectsTooLarge {
601            #[serde(with = "crate::_serde::ReadableDisplay")]
602            current_size: u64,
603            #[serde(with = "crate::_serde::ReadableDisplay")]
604            max_size: u64,
605        },
606        PublishUpgradeMissingDependency,
607        PublishUpgradeDependencyDowngrade,
608        PackageUpgradeError {
609            kind: PackageUpgradeError,
610        },
611        WrittenObjectsTooLarge {
612            #[serde(with = "crate::_serde::ReadableDisplay")]
613            object_size: u64,
614            #[serde(with = "crate::_serde::ReadableDisplay")]
615            max_object_size: u64,
616        },
617        CertificateDenied,
618        SuiMoveVerificationTimedout,
619        SharedObjectOperationNotAllowed,
620        InputObjectDeleted,
621        ExecutionCanceledDueToSharedObjectCongestion {
622            congested_objects: Vec<ObjectId>,
623        },
624
625        AddressDeniedForCoin {
626            address: Address,
627            coin_type: String,
628        },
629
630        CoinTypeGlobalPause {
631            coin_type: String,
632        },
633
634        ExecutionCanceledDueToRandomnessUnavailable,
635    }
636
637    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
638    enum BinaryExecutionError {
639        InsufficientGas,
640        InvalidGasObject,
641        InvariantViolation,
642        FeatureNotYetSupported,
643        ObjectTooBig {
644            object_size: u64,
645            max_object_size: u64,
646        },
647        PackageTooBig {
648            object_size: u64,
649            max_object_size: u64,
650        },
651        CircularObjectOwnership {
652            object: ObjectId,
653        },
654        InsufficientCoinBalance,
655        CoinBalanceOverflow,
656        PublishErrorNonZeroAddress,
657        SuiMoveVerificationError,
658        MovePrimitiveRuntimeError {
659            location: Option<MoveLocation>,
660        },
661        MoveAbort {
662            location: MoveLocation,
663            code: u64,
664        },
665        VmVerificationOrDeserializationError,
666        VmInvariantViolation,
667        FunctionNotFound,
668        ArityMismatch,
669        TypeArityMismatch,
670        NonEntryFunctionInvoked,
671        CommandArgumentError {
672            argument: u16,
673            kind: CommandArgumentError,
674        },
675        TypeArgumentError {
676            type_argument: u16,
677            kind: TypeArgumentError,
678        },
679        UnusedValueWithoutDrop {
680            result: u16,
681            subresult: u16,
682        },
683        InvalidPublicFunctionReturnType {
684            index: u16,
685        },
686        InvalidTransferObject,
687        EffectsTooLarge {
688            current_size: u64,
689            max_size: u64,
690        },
691        PublishUpgradeMissingDependency,
692        PublishUpgradeDependencyDowngrade,
693        PackageUpgradeError {
694            kind: PackageUpgradeError,
695        },
696        WrittenObjectsTooLarge {
697            object_size: u64,
698            max_object_size: u64,
699        },
700        CertificateDenied,
701        SuiMoveVerificationTimedout,
702        SharedObjectOperationNotAllowed,
703        InputObjectDeleted,
704        ExecutionCanceledDueToSharedObjectCongestion {
705            congested_objects: Vec<ObjectId>,
706        },
707
708        AddressDeniedForCoin {
709            address: Address,
710            coin_type: String,
711        },
712
713        CoinTypeGlobalPause {
714            coin_type: String,
715        },
716
717        ExecutionCanceledDueToRandomnessUnavailable,
718    }
719
720    impl Serialize for ExecutionError {
721        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
722        where
723            S: Serializer,
724        {
725            if serializer.is_human_readable() {
726                let readable = match self.clone() {
727                    Self::InsufficientGas => ReadableExecutionError::InsufficientGas,
728                    Self::InvalidGasObject => ReadableExecutionError::InvalidGasObject,
729                    Self::InvariantViolation => ReadableExecutionError::InvariantViolation,
730                    Self::FeatureNotYetSupported => ReadableExecutionError::FeatureNotYetSupported,
731                    Self::ObjectTooBig {
732                        object_size,
733                        max_object_size,
734                    } => ReadableExecutionError::ObjectTooBig {
735                        object_size,
736                        max_object_size,
737                    },
738                    Self::PackageTooBig {
739                        object_size,
740                        max_object_size,
741                    } => ReadableExecutionError::PackageTooBig {
742                        object_size,
743                        max_object_size,
744                    },
745                    Self::CircularObjectOwnership { object } => {
746                        ReadableExecutionError::CircularObjectOwnership { object }
747                    }
748                    Self::InsufficientCoinBalance => {
749                        ReadableExecutionError::InsufficientCoinBalance
750                    }
751                    Self::CoinBalanceOverflow => ReadableExecutionError::CoinBalanceOverflow,
752                    Self::PublishErrorNonZeroAddress => {
753                        ReadableExecutionError::PublishErrorNonZeroAddress
754                    }
755                    Self::SuiMoveVerificationError => {
756                        ReadableExecutionError::SuiMoveVerificationError
757                    }
758                    Self::MovePrimitiveRuntimeError { location } => {
759                        ReadableExecutionError::MovePrimitiveRuntimeError { location }
760                    }
761                    Self::MoveAbort { location, code } => {
762                        ReadableExecutionError::MoveAbort { location, code }
763                    }
764                    Self::VmVerificationOrDeserializationError => {
765                        ReadableExecutionError::VmVerificationOrDeserializationError
766                    }
767                    Self::VmInvariantViolation => ReadableExecutionError::VmInvariantViolation,
768                    Self::FunctionNotFound => ReadableExecutionError::FunctionNotFound,
769                    Self::ArityMismatch => ReadableExecutionError::ArityMismatch,
770                    Self::TypeArityMismatch => ReadableExecutionError::TypeArityMismatch,
771                    Self::NonEntryFunctionInvoked => {
772                        ReadableExecutionError::NonEntryFunctionInvoked
773                    }
774                    Self::CommandArgumentError { argument, kind } => {
775                        ReadableExecutionError::CommandArgumentError { argument, kind }
776                    }
777                    Self::TypeArgumentError {
778                        type_argument,
779                        kind,
780                    } => ReadableExecutionError::TypeArgumentError {
781                        type_argument,
782                        kind,
783                    },
784                    Self::UnusedValueWithoutDrop { result, subresult } => {
785                        ReadableExecutionError::UnusedValueWithoutDrop { result, subresult }
786                    }
787                    Self::InvalidPublicFunctionReturnType { index } => {
788                        ReadableExecutionError::InvalidPublicFunctionReturnType { index }
789                    }
790                    Self::InvalidTransferObject => ReadableExecutionError::InvalidTransferObject,
791                    Self::EffectsTooLarge {
792                        current_size,
793                        max_size,
794                    } => ReadableExecutionError::EffectsTooLarge {
795                        current_size,
796                        max_size,
797                    },
798                    Self::PublishUpgradeMissingDependency => {
799                        ReadableExecutionError::PublishUpgradeMissingDependency
800                    }
801                    Self::PublishUpgradeDependencyDowngrade => {
802                        ReadableExecutionError::PublishUpgradeDependencyDowngrade
803                    }
804                    Self::PackageUpgradeError { kind } => {
805                        ReadableExecutionError::PackageUpgradeError { kind }
806                    }
807                    Self::WrittenObjectsTooLarge {
808                        object_size,
809                        max_object_size,
810                    } => ReadableExecutionError::WrittenObjectsTooLarge {
811                        object_size,
812                        max_object_size,
813                    },
814                    Self::CertificateDenied => ReadableExecutionError::CertificateDenied,
815                    Self::SuiMoveVerificationTimedout => {
816                        ReadableExecutionError::SuiMoveVerificationTimedout
817                    }
818                    Self::SharedObjectOperationNotAllowed => {
819                        ReadableExecutionError::SharedObjectOperationNotAllowed
820                    }
821                    Self::InputObjectDeleted => ReadableExecutionError::InputObjectDeleted,
822                    Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
823                        ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
824                            congested_objects,
825                        }
826                    }
827                    Self::AddressDeniedForCoin { address, coin_type } => {
828                        ReadableExecutionError::AddressDeniedForCoin { address, coin_type }
829                    }
830                    Self::CoinTypeGlobalPause { coin_type } => {
831                        ReadableExecutionError::CoinTypeGlobalPause { coin_type }
832                    }
833                    Self::ExecutionCanceledDueToRandomnessUnavailable => {
834                        ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable
835                    }
836                };
837                readable.serialize(serializer)
838            } else {
839                let binary = match self.clone() {
840                    Self::InsufficientGas => BinaryExecutionError::InsufficientGas,
841                    Self::InvalidGasObject => BinaryExecutionError::InvalidGasObject,
842                    Self::InvariantViolation => BinaryExecutionError::InvariantViolation,
843                    Self::FeatureNotYetSupported => BinaryExecutionError::FeatureNotYetSupported,
844                    Self::ObjectTooBig {
845                        object_size,
846                        max_object_size,
847                    } => BinaryExecutionError::ObjectTooBig {
848                        object_size,
849                        max_object_size,
850                    },
851                    Self::PackageTooBig {
852                        object_size,
853                        max_object_size,
854                    } => BinaryExecutionError::PackageTooBig {
855                        object_size,
856                        max_object_size,
857                    },
858                    Self::CircularObjectOwnership { object } => {
859                        BinaryExecutionError::CircularObjectOwnership { object }
860                    }
861                    Self::InsufficientCoinBalance => BinaryExecutionError::InsufficientCoinBalance,
862                    Self::CoinBalanceOverflow => BinaryExecutionError::CoinBalanceOverflow,
863                    Self::PublishErrorNonZeroAddress => {
864                        BinaryExecutionError::PublishErrorNonZeroAddress
865                    }
866                    Self::SuiMoveVerificationError => {
867                        BinaryExecutionError::SuiMoveVerificationError
868                    }
869                    Self::MovePrimitiveRuntimeError { location } => {
870                        BinaryExecutionError::MovePrimitiveRuntimeError { location }
871                    }
872                    Self::MoveAbort { location, code } => {
873                        BinaryExecutionError::MoveAbort { location, code }
874                    }
875                    Self::VmVerificationOrDeserializationError => {
876                        BinaryExecutionError::VmVerificationOrDeserializationError
877                    }
878                    Self::VmInvariantViolation => BinaryExecutionError::VmInvariantViolation,
879                    Self::FunctionNotFound => BinaryExecutionError::FunctionNotFound,
880                    Self::ArityMismatch => BinaryExecutionError::ArityMismatch,
881                    Self::TypeArityMismatch => BinaryExecutionError::TypeArityMismatch,
882                    Self::NonEntryFunctionInvoked => BinaryExecutionError::NonEntryFunctionInvoked,
883                    Self::CommandArgumentError { argument, kind } => {
884                        BinaryExecutionError::CommandArgumentError { argument, kind }
885                    }
886                    Self::TypeArgumentError {
887                        type_argument,
888                        kind,
889                    } => BinaryExecutionError::TypeArgumentError {
890                        type_argument,
891                        kind,
892                    },
893                    Self::UnusedValueWithoutDrop { result, subresult } => {
894                        BinaryExecutionError::UnusedValueWithoutDrop { result, subresult }
895                    }
896                    Self::InvalidPublicFunctionReturnType { index } => {
897                        BinaryExecutionError::InvalidPublicFunctionReturnType { index }
898                    }
899                    Self::InvalidTransferObject => BinaryExecutionError::InvalidTransferObject,
900                    Self::EffectsTooLarge {
901                        current_size,
902                        max_size,
903                    } => BinaryExecutionError::EffectsTooLarge {
904                        current_size,
905                        max_size,
906                    },
907                    Self::PublishUpgradeMissingDependency => {
908                        BinaryExecutionError::PublishUpgradeMissingDependency
909                    }
910                    Self::PublishUpgradeDependencyDowngrade => {
911                        BinaryExecutionError::PublishUpgradeDependencyDowngrade
912                    }
913                    Self::PackageUpgradeError { kind } => {
914                        BinaryExecutionError::PackageUpgradeError { kind }
915                    }
916                    Self::WrittenObjectsTooLarge {
917                        object_size,
918                        max_object_size,
919                    } => BinaryExecutionError::WrittenObjectsTooLarge {
920                        object_size,
921                        max_object_size,
922                    },
923                    Self::CertificateDenied => BinaryExecutionError::CertificateDenied,
924                    Self::SuiMoveVerificationTimedout => {
925                        BinaryExecutionError::SuiMoveVerificationTimedout
926                    }
927                    Self::SharedObjectOperationNotAllowed => {
928                        BinaryExecutionError::SharedObjectOperationNotAllowed
929                    }
930                    Self::InputObjectDeleted => BinaryExecutionError::InputObjectDeleted,
931                    Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects } => {
932                        BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
933                            congested_objects,
934                        }
935                    }
936                    Self::AddressDeniedForCoin { address, coin_type } => {
937                        BinaryExecutionError::AddressDeniedForCoin { address, coin_type }
938                    }
939                    Self::CoinTypeGlobalPause { coin_type } => {
940                        BinaryExecutionError::CoinTypeGlobalPause { coin_type }
941                    }
942                    Self::ExecutionCanceledDueToRandomnessUnavailable => {
943                        BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable
944                    }
945                };
946                binary.serialize(serializer)
947            }
948        }
949    }
950
951    impl<'de> Deserialize<'de> for ExecutionError {
952        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
953        where
954            D: Deserializer<'de>,
955        {
956            if deserializer.is_human_readable() {
957                ReadableExecutionError::deserialize(deserializer).map(|readable| match readable {
958                    ReadableExecutionError::InsufficientGas => Self::InsufficientGas,
959                    ReadableExecutionError::InvalidGasObject => Self::InvalidGasObject,
960                    ReadableExecutionError::InvariantViolation => Self::InvariantViolation,
961                    ReadableExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
962                    ReadableExecutionError::ObjectTooBig {
963                        object_size,
964                        max_object_size,
965                    } => Self::ObjectTooBig {
966                        object_size,
967                        max_object_size,
968                    },
969                    ReadableExecutionError::PackageTooBig {
970                        object_size,
971                        max_object_size,
972                    } => Self::PackageTooBig {
973                        object_size,
974                        max_object_size,
975                    },
976                    ReadableExecutionError::CircularObjectOwnership { object } => {
977                        Self::CircularObjectOwnership { object }
978                    }
979                    ReadableExecutionError::InsufficientCoinBalance => {
980                        Self::InsufficientCoinBalance
981                    }
982                    ReadableExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
983                    ReadableExecutionError::PublishErrorNonZeroAddress => {
984                        Self::PublishErrorNonZeroAddress
985                    }
986                    ReadableExecutionError::SuiMoveVerificationError => {
987                        Self::SuiMoveVerificationError
988                    }
989                    ReadableExecutionError::MovePrimitiveRuntimeError { location } => {
990                        Self::MovePrimitiveRuntimeError { location }
991                    }
992                    ReadableExecutionError::MoveAbort { location, code } => {
993                        Self::MoveAbort { location, code }
994                    }
995                    ReadableExecutionError::VmVerificationOrDeserializationError => {
996                        Self::VmVerificationOrDeserializationError
997                    }
998                    ReadableExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
999                    ReadableExecutionError::FunctionNotFound => Self::FunctionNotFound,
1000                    ReadableExecutionError::ArityMismatch => Self::ArityMismatch,
1001                    ReadableExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1002                    ReadableExecutionError::NonEntryFunctionInvoked => {
1003                        Self::NonEntryFunctionInvoked
1004                    }
1005                    ReadableExecutionError::CommandArgumentError { argument, kind } => {
1006                        Self::CommandArgumentError { argument, kind }
1007                    }
1008                    ReadableExecutionError::TypeArgumentError {
1009                        type_argument,
1010                        kind,
1011                    } => Self::TypeArgumentError {
1012                        type_argument,
1013                        kind,
1014                    },
1015                    ReadableExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1016                        Self::UnusedValueWithoutDrop { result, subresult }
1017                    }
1018                    ReadableExecutionError::InvalidPublicFunctionReturnType { index } => {
1019                        Self::InvalidPublicFunctionReturnType { index }
1020                    }
1021                    ReadableExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1022                    ReadableExecutionError::EffectsTooLarge {
1023                        current_size,
1024                        max_size,
1025                    } => Self::EffectsTooLarge {
1026                        current_size,
1027                        max_size,
1028                    },
1029                    ReadableExecutionError::PublishUpgradeMissingDependency => {
1030                        Self::PublishUpgradeMissingDependency
1031                    }
1032                    ReadableExecutionError::PublishUpgradeDependencyDowngrade => {
1033                        Self::PublishUpgradeDependencyDowngrade
1034                    }
1035                    ReadableExecutionError::PackageUpgradeError { kind } => {
1036                        Self::PackageUpgradeError { kind }
1037                    }
1038                    ReadableExecutionError::WrittenObjectsTooLarge {
1039                        object_size,
1040                        max_object_size,
1041                    } => Self::WrittenObjectsTooLarge {
1042                        object_size,
1043                        max_object_size,
1044                    },
1045                    ReadableExecutionError::CertificateDenied => Self::CertificateDenied,
1046                    ReadableExecutionError::SuiMoveVerificationTimedout => {
1047                        Self::SuiMoveVerificationTimedout
1048                    }
1049                    ReadableExecutionError::SharedObjectOperationNotAllowed => {
1050                        Self::SharedObjectOperationNotAllowed
1051                    }
1052                    ReadableExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1053                    ReadableExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1054                        congested_objects,
1055                    } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1056                    ReadableExecutionError::AddressDeniedForCoin { address, coin_type } => {
1057                        Self::AddressDeniedForCoin { address, coin_type }
1058                    }
1059                    ReadableExecutionError::CoinTypeGlobalPause { coin_type } => {
1060                        Self::CoinTypeGlobalPause { coin_type }
1061                    }
1062                    ReadableExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1063                        Self::ExecutionCanceledDueToRandomnessUnavailable
1064                    }
1065                })
1066            } else {
1067                BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
1068                    BinaryExecutionError::InsufficientGas => Self::InsufficientGas,
1069                    BinaryExecutionError::InvalidGasObject => Self::InvalidGasObject,
1070                    BinaryExecutionError::InvariantViolation => Self::InvariantViolation,
1071                    BinaryExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1072                    BinaryExecutionError::ObjectTooBig {
1073                        object_size,
1074                        max_object_size,
1075                    } => Self::ObjectTooBig {
1076                        object_size,
1077                        max_object_size,
1078                    },
1079                    BinaryExecutionError::PackageTooBig {
1080                        object_size,
1081                        max_object_size,
1082                    } => Self::PackageTooBig {
1083                        object_size,
1084                        max_object_size,
1085                    },
1086                    BinaryExecutionError::CircularObjectOwnership { object } => {
1087                        Self::CircularObjectOwnership { object }
1088                    }
1089                    BinaryExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
1090                    BinaryExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1091                    BinaryExecutionError::PublishErrorNonZeroAddress => {
1092                        Self::PublishErrorNonZeroAddress
1093                    }
1094                    BinaryExecutionError::SuiMoveVerificationError => {
1095                        Self::SuiMoveVerificationError
1096                    }
1097                    BinaryExecutionError::MovePrimitiveRuntimeError { location } => {
1098                        Self::MovePrimitiveRuntimeError { location }
1099                    }
1100                    BinaryExecutionError::MoveAbort { location, code } => {
1101                        Self::MoveAbort { location, code }
1102                    }
1103                    BinaryExecutionError::VmVerificationOrDeserializationError => {
1104                        Self::VmVerificationOrDeserializationError
1105                    }
1106                    BinaryExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1107                    BinaryExecutionError::FunctionNotFound => Self::FunctionNotFound,
1108                    BinaryExecutionError::ArityMismatch => Self::ArityMismatch,
1109                    BinaryExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1110                    BinaryExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
1111                    BinaryExecutionError::CommandArgumentError { argument, kind } => {
1112                        Self::CommandArgumentError { argument, kind }
1113                    }
1114                    BinaryExecutionError::TypeArgumentError {
1115                        type_argument,
1116                        kind,
1117                    } => Self::TypeArgumentError {
1118                        type_argument,
1119                        kind,
1120                    },
1121                    BinaryExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1122                        Self::UnusedValueWithoutDrop { result, subresult }
1123                    }
1124                    BinaryExecutionError::InvalidPublicFunctionReturnType { index } => {
1125                        Self::InvalidPublicFunctionReturnType { index }
1126                    }
1127                    BinaryExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1128                    BinaryExecutionError::EffectsTooLarge {
1129                        current_size,
1130                        max_size,
1131                    } => Self::EffectsTooLarge {
1132                        current_size,
1133                        max_size,
1134                    },
1135                    BinaryExecutionError::PublishUpgradeMissingDependency => {
1136                        Self::PublishUpgradeMissingDependency
1137                    }
1138                    BinaryExecutionError::PublishUpgradeDependencyDowngrade => {
1139                        Self::PublishUpgradeDependencyDowngrade
1140                    }
1141                    BinaryExecutionError::PackageUpgradeError { kind } => {
1142                        Self::PackageUpgradeError { kind }
1143                    }
1144                    BinaryExecutionError::WrittenObjectsTooLarge {
1145                        object_size,
1146                        max_object_size,
1147                    } => Self::WrittenObjectsTooLarge {
1148                        object_size,
1149                        max_object_size,
1150                    },
1151                    BinaryExecutionError::CertificateDenied => Self::CertificateDenied,
1152                    BinaryExecutionError::SuiMoveVerificationTimedout => {
1153                        Self::SuiMoveVerificationTimedout
1154                    }
1155                    BinaryExecutionError::SharedObjectOperationNotAllowed => {
1156                        Self::SharedObjectOperationNotAllowed
1157                    }
1158                    BinaryExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1159                    BinaryExecutionError::ExecutionCanceledDueToSharedObjectCongestion {
1160                        congested_objects,
1161                    } => Self::ExecutionCanceledDueToSharedObjectCongestion { congested_objects },
1162                    BinaryExecutionError::AddressDeniedForCoin { address, coin_type } => {
1163                        Self::AddressDeniedForCoin { address, coin_type }
1164                    }
1165                    BinaryExecutionError::CoinTypeGlobalPause { coin_type } => {
1166                        Self::CoinTypeGlobalPause { coin_type }
1167                    }
1168                    BinaryExecutionError::ExecutionCanceledDueToRandomnessUnavailable => {
1169                        Self::ExecutionCanceledDueToRandomnessUnavailable
1170                    }
1171                })
1172            }
1173        }
1174    }
1175
1176    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1177    #[serde(tag = "kind", rename_all = "snake_case")]
1178    enum ReadableCommandArgumentError {
1179        TypeMismatch,
1180        InvalidBcsBytes,
1181        InvalidUsageOfPureArgument,
1182        InvalidArgumentToPrivateEntryFunction,
1183        IndexOutOfBounds { index: u16 },
1184        SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1185        InvalidResultArity { result: u16 },
1186        InvalidGasCoinUsage,
1187        InvalidValueUsage,
1188        InvalidObjectByValue,
1189        InvalidObjectByMutRef,
1190        SharedObjectOperationNotAllowed,
1191    }
1192
1193    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1194    enum BinaryCommandArgumentError {
1195        TypeMismatch,
1196        InvalidBcsBytes,
1197        InvalidUsageOfPureArgument,
1198        InvalidArgumentToPrivateEntryFunction,
1199        IndexOutOfBounds { index: u16 },
1200        SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1201        InvalidResultArity { result: u16 },
1202        InvalidGasCoinUsage,
1203        InvalidValueUsage,
1204        InvalidObjectByValue,
1205        InvalidObjectByMutRef,
1206        SharedObjectOperationNotAllowed,
1207    }
1208
1209    impl Serialize for CommandArgumentError {
1210        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1211        where
1212            S: Serializer,
1213        {
1214            if serializer.is_human_readable() {
1215                let readable = match self.clone() {
1216                    Self::TypeMismatch => ReadableCommandArgumentError::TypeMismatch,
1217                    Self::InvalidBcsBytes => ReadableCommandArgumentError::InvalidBcsBytes,
1218                    Self::InvalidUsageOfPureArgument => {
1219                        ReadableCommandArgumentError::InvalidUsageOfPureArgument
1220                    }
1221                    Self::InvalidArgumentToPrivateEntryFunction => {
1222                        ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1223                    }
1224                    Self::IndexOutOfBounds { index } => {
1225                        ReadableCommandArgumentError::IndexOutOfBounds { index }
1226                    }
1227                    Self::SecondaryIndexOutOfBounds { result, subresult } => {
1228                        ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1229                            result,
1230                            subresult,
1231                        }
1232                    }
1233                    Self::InvalidResultArity { result } => {
1234                        ReadableCommandArgumentError::InvalidResultArity { result }
1235                    }
1236                    Self::InvalidGasCoinUsage => ReadableCommandArgumentError::InvalidGasCoinUsage,
1237                    Self::InvalidValueUsage => ReadableCommandArgumentError::InvalidValueUsage,
1238                    Self::InvalidObjectByValue => {
1239                        ReadableCommandArgumentError::InvalidObjectByValue
1240                    }
1241                    Self::InvalidObjectByMutRef => {
1242                        ReadableCommandArgumentError::InvalidObjectByMutRef
1243                    }
1244                    Self::SharedObjectOperationNotAllowed => {
1245                        ReadableCommandArgumentError::SharedObjectOperationNotAllowed
1246                    }
1247                };
1248                readable.serialize(serializer)
1249            } else {
1250                let binary = match self.clone() {
1251                    Self::TypeMismatch => BinaryCommandArgumentError::TypeMismatch,
1252                    Self::InvalidBcsBytes => BinaryCommandArgumentError::InvalidBcsBytes,
1253                    Self::InvalidUsageOfPureArgument => {
1254                        BinaryCommandArgumentError::InvalidUsageOfPureArgument
1255                    }
1256                    Self::InvalidArgumentToPrivateEntryFunction => {
1257                        BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1258                    }
1259                    Self::IndexOutOfBounds { index } => {
1260                        BinaryCommandArgumentError::IndexOutOfBounds { index }
1261                    }
1262                    Self::SecondaryIndexOutOfBounds { result, subresult } => {
1263                        BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult }
1264                    }
1265                    Self::InvalidResultArity { result } => {
1266                        BinaryCommandArgumentError::InvalidResultArity { result }
1267                    }
1268                    Self::InvalidGasCoinUsage => BinaryCommandArgumentError::InvalidGasCoinUsage,
1269                    Self::InvalidValueUsage => BinaryCommandArgumentError::InvalidValueUsage,
1270                    Self::InvalidObjectByValue => BinaryCommandArgumentError::InvalidObjectByValue,
1271                    Self::InvalidObjectByMutRef => {
1272                        BinaryCommandArgumentError::InvalidObjectByMutRef
1273                    }
1274                    Self::SharedObjectOperationNotAllowed => {
1275                        BinaryCommandArgumentError::SharedObjectOperationNotAllowed
1276                    }
1277                };
1278                binary.serialize(serializer)
1279            }
1280        }
1281    }
1282
1283    impl<'de> Deserialize<'de> for CommandArgumentError {
1284        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1285        where
1286            D: Deserializer<'de>,
1287        {
1288            if deserializer.is_human_readable() {
1289                ReadableCommandArgumentError::deserialize(deserializer).map(|readable| {
1290                    match readable {
1291                        ReadableCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1292                        ReadableCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1293                        ReadableCommandArgumentError::InvalidUsageOfPureArgument => {
1294                            Self::InvalidUsageOfPureArgument
1295                        }
1296                        ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1297                            Self::InvalidArgumentToPrivateEntryFunction
1298                        }
1299                        ReadableCommandArgumentError::IndexOutOfBounds { index } => {
1300                            Self::IndexOutOfBounds { index }
1301                        }
1302                        ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1303                            result,
1304                            subresult,
1305                        } => Self::SecondaryIndexOutOfBounds { result, subresult },
1306                        ReadableCommandArgumentError::InvalidResultArity { result } => {
1307                            Self::InvalidResultArity { result }
1308                        }
1309                        ReadableCommandArgumentError::InvalidGasCoinUsage => {
1310                            Self::InvalidGasCoinUsage
1311                        }
1312                        ReadableCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1313                        ReadableCommandArgumentError::InvalidObjectByValue => {
1314                            Self::InvalidObjectByValue
1315                        }
1316                        ReadableCommandArgumentError::InvalidObjectByMutRef => {
1317                            Self::InvalidObjectByMutRef
1318                        }
1319                        ReadableCommandArgumentError::SharedObjectOperationNotAllowed => {
1320                            Self::SharedObjectOperationNotAllowed
1321                        }
1322                    }
1323                })
1324            } else {
1325                BinaryCommandArgumentError::deserialize(deserializer).map(|binary| match binary {
1326                    BinaryCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1327                    BinaryCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1328                    BinaryCommandArgumentError::InvalidUsageOfPureArgument => {
1329                        Self::InvalidUsageOfPureArgument
1330                    }
1331                    BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1332                        Self::InvalidArgumentToPrivateEntryFunction
1333                    }
1334                    BinaryCommandArgumentError::IndexOutOfBounds { index } => {
1335                        Self::IndexOutOfBounds { index }
1336                    }
1337                    BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
1338                        Self::SecondaryIndexOutOfBounds { result, subresult }
1339                    }
1340                    BinaryCommandArgumentError::InvalidResultArity { result } => {
1341                        Self::InvalidResultArity { result }
1342                    }
1343                    BinaryCommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
1344                    BinaryCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1345                    BinaryCommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
1346                    BinaryCommandArgumentError::InvalidObjectByMutRef => {
1347                        Self::InvalidObjectByMutRef
1348                    }
1349                    BinaryCommandArgumentError::SharedObjectOperationNotAllowed => {
1350                        Self::SharedObjectOperationNotAllowed
1351                    }
1352                })
1353            }
1354        }
1355    }
1356
1357    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1358    #[serde(tag = "kind", rename_all = "snake_case")]
1359    enum ReadablePackageUpgradeError {
1360        UnableToFetchPackage {
1361            package_id: ObjectId,
1362        },
1363        NotAPackage {
1364            object_id: ObjectId,
1365        },
1366        IncompatibleUpgrade,
1367        DigestDoesNotMatch {
1368            digest: Digest,
1369        },
1370        UnknownUpgradePolicy {
1371            policy: u8,
1372        },
1373        PackageIdDoesNotMatch {
1374            package_id: ObjectId,
1375            ticket_id: ObjectId,
1376        },
1377    }
1378
1379    #[derive(serde_derive::Serialize, serde_derive::Deserialize)]
1380    enum BinaryPackageUpgradeError {
1381        UnableToFetchPackage {
1382            package_id: ObjectId,
1383        },
1384        NotAPackage {
1385            object_id: ObjectId,
1386        },
1387        IncompatibleUpgrade,
1388        DigestDoesNotMatch {
1389            digest: Digest,
1390        },
1391        UnknownUpgradePolicy {
1392            policy: u8,
1393        },
1394        PackageIdDoesNotMatch {
1395            package_id: ObjectId,
1396            ticket_id: ObjectId,
1397        },
1398    }
1399
1400    impl Serialize for PackageUpgradeError {
1401        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1402        where
1403            S: Serializer,
1404        {
1405            if serializer.is_human_readable() {
1406                let readable = match self.clone() {
1407                    Self::UnableToFetchPackage { package_id } => {
1408                        ReadablePackageUpgradeError::UnableToFetchPackage { package_id }
1409                    }
1410                    Self::NotAPackage { object_id } => {
1411                        ReadablePackageUpgradeError::NotAPackage { object_id }
1412                    }
1413                    Self::IncompatibleUpgrade => ReadablePackageUpgradeError::IncompatibleUpgrade,
1414                    Self::DigestDoesNotMatch { digest } => {
1415                        ReadablePackageUpgradeError::DigestDoesNotMatch { digest }
1416                    }
1417                    Self::UnknownUpgradePolicy { policy } => {
1418                        ReadablePackageUpgradeError::UnknownUpgradePolicy { policy }
1419                    }
1420                    Self::PackageIdDoesNotMatch {
1421                        package_id,
1422                        ticket_id,
1423                    } => ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1424                        package_id,
1425                        ticket_id,
1426                    },
1427                };
1428                readable.serialize(serializer)
1429            } else {
1430                let binary = match self.clone() {
1431                    Self::UnableToFetchPackage { package_id } => {
1432                        BinaryPackageUpgradeError::UnableToFetchPackage { package_id }
1433                    }
1434                    Self::NotAPackage { object_id } => {
1435                        BinaryPackageUpgradeError::NotAPackage { object_id }
1436                    }
1437                    Self::IncompatibleUpgrade => BinaryPackageUpgradeError::IncompatibleUpgrade,
1438                    Self::DigestDoesNotMatch { digest } => {
1439                        BinaryPackageUpgradeError::DigestDoesNotMatch { digest }
1440                    }
1441                    Self::UnknownUpgradePolicy { policy } => {
1442                        BinaryPackageUpgradeError::UnknownUpgradePolicy { policy }
1443                    }
1444                    Self::PackageIdDoesNotMatch {
1445                        package_id,
1446                        ticket_id,
1447                    } => BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1448                        package_id,
1449                        ticket_id,
1450                    },
1451                };
1452                binary.serialize(serializer)
1453            }
1454        }
1455    }
1456
1457    impl<'de> Deserialize<'de> for PackageUpgradeError {
1458        fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1459        where
1460            D: Deserializer<'de>,
1461        {
1462            if deserializer.is_human_readable() {
1463                ReadablePackageUpgradeError::deserialize(deserializer).map(
1464                    |readable| match readable {
1465                        ReadablePackageUpgradeError::UnableToFetchPackage { package_id } => {
1466                            Self::UnableToFetchPackage { package_id }
1467                        }
1468                        ReadablePackageUpgradeError::NotAPackage { object_id } => {
1469                            Self::NotAPackage { object_id }
1470                        }
1471                        ReadablePackageUpgradeError::IncompatibleUpgrade => {
1472                            Self::IncompatibleUpgrade
1473                        }
1474                        ReadablePackageUpgradeError::DigestDoesNotMatch { digest } => {
1475                            Self::DigestDoesNotMatch { digest }
1476                        }
1477                        ReadablePackageUpgradeError::UnknownUpgradePolicy { policy } => {
1478                            Self::UnknownUpgradePolicy { policy }
1479                        }
1480                        ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1481                            package_id,
1482                            ticket_id,
1483                        } => Self::PackageIdDoesNotMatch {
1484                            package_id,
1485                            ticket_id,
1486                        },
1487                    },
1488                )
1489            } else {
1490                BinaryPackageUpgradeError::deserialize(deserializer).map(|binary| match binary {
1491                    BinaryPackageUpgradeError::UnableToFetchPackage { package_id } => {
1492                        Self::UnableToFetchPackage { package_id }
1493                    }
1494                    BinaryPackageUpgradeError::NotAPackage { object_id } => {
1495                        Self::NotAPackage { object_id }
1496                    }
1497                    BinaryPackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
1498                    BinaryPackageUpgradeError::DigestDoesNotMatch { digest } => {
1499                        Self::DigestDoesNotMatch { digest }
1500                    }
1501                    BinaryPackageUpgradeError::UnknownUpgradePolicy { policy } => {
1502                        Self::UnknownUpgradePolicy { policy }
1503                    }
1504                    BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1505                        package_id,
1506                        ticket_id,
1507                    } => Self::PackageIdDoesNotMatch {
1508                        package_id,
1509                        ticket_id,
1510                    },
1511                })
1512            }
1513        }
1514    }
1515}