1use super::{Address, Digest, Identifier, ObjectId};
6
7#[derive(Eq, PartialEq, Clone, Debug)]
19#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
20pub enum ExecutionStatus {
21 Success,
23 Failure {
30 error: ExecutionError,
32 #[cfg_attr(feature = "proptest", map(|x: Option<u16>| x.map(Into::into)))]
34 command: Option<u64>,
35 },
36}
37
38impl ExecutionStatus {
39 crate::def_is!(Success, Failure);
40
41 pub fn error(&self) -> Option<&ExecutionError> {
43 if let Self::Failure { error, .. } = self {
44 Some(error)
45 } else {
46 None
47 }
48 }
49
50 pub fn error_command(&self) -> Option<u64> {
52 if let Self::Failure { command, .. } = self {
53 *command
54 } else {
55 None
56 }
57 }
58}
59
60#[derive(Eq, PartialEq, Clone, Debug)]
145#[cfg_attr(
146 feature = "schemars",
147 derive(schemars::JsonSchema),
148 schemars(tag = "error", rename_all = "snake_case")
149)]
150#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
151pub enum ExecutionError {
152 InsufficientGas,
154 InvalidGasObject,
156 InvariantViolation,
158 FeatureNotYetSupported,
160 ObjectTooBig {
162 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
163 object_size: u64,
164 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
165 max_object_size: u64,
166 },
167 PackageTooBig {
169 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
170 object_size: u64,
171 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
172 max_object_size: u64,
173 },
174 CircularObjectOwnership { object: ObjectId },
176 InsufficientCoinBalance,
178 CoinBalanceOverflow,
180 PublishErrorNonZeroAddress,
183 IotaMoveVerificationError,
185 MovePrimitiveRuntimeError { location: Option<MoveLocation> },
189 MoveAbort {
191 location: MoveLocation,
192 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
193 code: u64,
194 },
195 VmVerificationOrDeserializationError,
197 VmInvariantViolation,
199 FunctionNotFound,
201 ArityMismatch,
204 TypeArityMismatch,
207 NonEntryFunctionInvoked,
209 CommandArgumentError {
211 argument: u16,
212 kind: CommandArgumentError,
213 },
214 TypeArgumentError {
216 type_argument: u16,
218 kind: TypeArgumentError,
219 },
220 UnusedValueWithoutDrop { result: u16, subresult: u16 },
222 InvalidPublicFunctionReturnType { index: u16 },
225 InvalidTransferObject,
227 EffectsTooLarge {
229 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
230 current_size: u64,
231 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
232 max_size: u64,
233 },
234 PublishUpgradeMissingDependency,
236 PublishUpgradeDependencyDowngrade,
242 #[cfg_attr(feature = "schemars", schemars(title = "PackageUpgradeError"))]
244 PackageUpgradeError { kind: PackageUpgradeError },
245 WrittenObjectsTooLarge {
247 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
248 object_size: u64,
249 #[cfg_attr(feature = "schemars", schemars(with = "crate::_schemars::U64"))]
250 max_object_size: u64,
251 },
252 CertificateDenied,
254 IotaMoveVerificationTimeout,
256 SharedObjectOperationNotAllowed,
258 InputObjectDeleted,
260 ExecutionCancelledDueToSharedObjectCongestion { congested_objects: Vec<ObjectId> },
262 ExecutionCancelledDueToSharedObjectCongestionV2 {
265 congested_objects: Vec<ObjectId>,
266 suggested_gas_price: u64,
267 },
268 AddressDeniedForCoin { address: Address, coin_type: String },
270 CoinTypeGlobalPause { coin_type: String },
272 ExecutionCancelledDueToRandomnessUnavailable,
275 InvalidLinkage,
278}
279
280impl ExecutionError {
281 crate::def_is!(
282 InsufficientGas,
283 InvalidGasObject,
284 InvariantViolation,
285 FeatureNotYetSupported,
286 ObjectTooBig,
287 PackageTooBig,
288 CircularObjectOwnership,
289 InsufficientCoinBalance,
290 CoinBalanceOverflow,
291 PublishErrorNonZeroAddress,
292 IotaMoveVerificationError,
293 MovePrimitiveRuntimeError,
294 MoveAbort,
295 VmVerificationOrDeserializationError,
296 VmInvariantViolation,
297 FunctionNotFound,
298 ArityMismatch,
299 TypeArityMismatch,
300 NonEntryFunctionInvoked,
301 CommandArgumentError,
302 TypeArgumentError,
303 UnusedValueWithoutDrop,
304 InvalidPublicFunctionReturnType,
305 InvalidTransferObject,
306 EffectsTooLarge,
307 PublishUpgradeMissingDependency,
308 PublishUpgradeDependencyDowngrade,
309 PackageUpgradeError,
310 WrittenObjectsTooLarge,
311 CertificateDenied,
312 IotaMoveVerificationTimeout,
313 SharedObjectOperationNotAllowed,
314 InputObjectDeleted,
315 ExecutionCancelledDueToSharedObjectCongestion,
316 ExecutionCancelledDueToSharedObjectCongestionV2,
317 AddressDeniedForCoin,
318 CoinTypeGlobalPause,
319 ExecutionCancelledDueToRandomnessUnavailable,
320 InvalidLinkage,
321 );
322}
323
324#[derive(Eq, PartialEq, Clone, Debug)]
334#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
335#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
336#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
337pub struct MoveLocation {
338 pub package: ObjectId,
340 pub module: Identifier,
342 pub function: u16,
344 pub instruction: u16,
347 pub function_name: Option<Identifier>,
349}
350
351#[derive(Eq, PartialEq, Clone, Debug)]
385#[cfg_attr(
386 feature = "schemars",
387 derive(schemars::JsonSchema),
388 schemars(tag = "kind", rename_all = "snake_case")
389)]
390#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
391pub enum CommandArgumentError {
392 TypeMismatch,
394 InvalidBcsBytes,
396 InvalidUsageOfPureArgument,
398 InvalidArgumentToPrivateEntryFunction,
401 IndexOutOfBounds { index: u16 },
403 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
405 InvalidResultArity { result: u16 },
408 InvalidGasCoinUsage,
411 InvalidValueUsage,
416 InvalidObjectByValue,
418 InvalidObjectByMutRef,
420 SharedObjectOperationNotAllowed,
423 InvalidArgumentArity,
426}
427
428impl CommandArgumentError {
429 crate::def_is!(
430 TypeMismatch,
431 InvalidBcsBytes,
432 InvalidUsageOfPureArgument,
433 InvalidArgumentToPrivateEntryFunction,
434 IndexOutOfBounds,
435 SecondaryIndexOutOfBounds,
436 InvalidResultArity,
437 InvalidGasCoinUsage,
438 InvalidValueUsage,
439 InvalidObjectByValue,
440 InvalidObjectByMutRef,
441 SharedObjectOperationNotAllowed,
442 );
443}
444
445#[derive(Eq, PartialEq, Clone, Debug)]
467#[cfg_attr(
468 feature = "schemars",
469 derive(schemars::JsonSchema),
470 schemars(tag = "kind", rename_all = "snake_case")
471)]
472#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
473pub enum PackageUpgradeError {
474 UnableToFetchPackage { package_id: ObjectId },
476 NotAPackage { object_id: ObjectId },
478 IncompatibleUpgrade,
480 DigestDoesNotMatch { digest: Digest },
482 UnknownUpgradePolicy { policy: u8 },
484 PackageIdDoesNotMatch {
486 package_id: ObjectId,
487 ticket_id: ObjectId,
488 },
489}
490
491impl PackageUpgradeError {
492 crate::def_is!(
493 UnableToFetchPackage,
494 NotAPackage,
495 IncompatibleUpgrade,
496 DigestDoesNotMatch,
497 UnknownUpgradePolicy,
498 PackageIdDoesNotMatch,
499 );
500}
501
502#[derive(Eq, PartialEq, Clone, Copy, Debug)]
514#[cfg_attr(
515 feature = "serde",
516 derive(serde::Serialize, serde::Deserialize),
517 serde(rename_all = "snake_case")
518)]
519#[cfg_attr(
520 feature = "schemars",
521 derive(schemars::JsonSchema),
522 schemars(rename_all = "snake_case")
523)]
524#[cfg_attr(feature = "proptest", derive(test_strategy::Arbitrary))]
525pub enum TypeArgumentError {
526 TypeNotFound,
528 ConstraintNotSatisfied,
530}
531
532impl TypeArgumentError {
533 crate::def_is!(TypeNotFound, ConstraintNotSatisfied);
534}
535
536#[cfg(feature = "serde")]
537#[cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
538mod serialization {
539 use serde::{Deserialize, Deserializer, Serialize, Serializer};
540
541 use super::*;
542
543 #[derive(serde::Serialize, serde::Deserialize)]
544 #[serde(rename = "ExecutionStatus")]
545 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
546 struct ReadableExecutionStatus {
547 success: bool,
548 #[serde(skip_serializing_if = "Option::is_none")]
549 status: Option<FailureStatus>,
550 }
551
552 #[cfg(feature = "schemars")]
553 impl schemars::JsonSchema for ExecutionStatus {
554 fn schema_name() -> String {
555 ReadableExecutionStatus::schema_name()
556 }
557
558 fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
559 ReadableExecutionStatus::json_schema(gen)
560 }
561 }
562
563 #[derive(serde::Serialize, serde::Deserialize)]
564 #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
565 struct FailureStatus {
566 error: ExecutionError,
567 #[serde(skip_serializing_if = "Option::is_none")]
568 command: Option<u16>,
569 }
570
571 #[derive(serde::Serialize, serde::Deserialize)]
572 enum BinaryExecutionStatus {
573 Success,
574 Failure {
575 error: ExecutionError,
576 command: Option<u64>,
577 },
578 }
579
580 impl Serialize for ExecutionStatus {
581 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
582 where
583 S: Serializer,
584 {
585 if serializer.is_human_readable() {
586 let readable = match self.clone() {
587 ExecutionStatus::Success => ReadableExecutionStatus {
588 success: true,
589 status: None,
590 },
591 ExecutionStatus::Failure { error, command } => ReadableExecutionStatus {
592 success: false,
593 status: Some(FailureStatus {
594 error,
595 command: command.map(|c| c as u16),
596 }),
597 },
598 };
599 readable.serialize(serializer)
600 } else {
601 let binary = match self.clone() {
602 ExecutionStatus::Success => BinaryExecutionStatus::Success,
603 ExecutionStatus::Failure { error, command } => {
604 BinaryExecutionStatus::Failure { error, command }
605 }
606 };
607 binary.serialize(serializer)
608 }
609 }
610 }
611
612 impl<'de> Deserialize<'de> for ExecutionStatus {
613 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
614 where
615 D: Deserializer<'de>,
616 {
617 if deserializer.is_human_readable() {
618 let ReadableExecutionStatus { success, status } =
619 Deserialize::deserialize(deserializer)?;
620 match (success, status) {
621 (true, None) => Ok(ExecutionStatus::Success),
622 (false, Some(FailureStatus { error, command })) => {
623 Ok(ExecutionStatus::Failure {
624 error,
625 command: command.map(Into::into),
626 })
627 }
628 (true, Some(_)) | (false, None) => {
630 Err(serde::de::Error::custom("invalid execution status"))
631 }
632 }
633 } else {
634 BinaryExecutionStatus::deserialize(deserializer).map(|readable| match readable {
635 BinaryExecutionStatus::Success => Self::Success,
636 BinaryExecutionStatus::Failure { error, command } => {
637 Self::Failure { error, command }
638 }
639 })
640 }
641 }
642 }
643
644 #[derive(serde::Serialize, serde::Deserialize)]
645 #[serde(tag = "error", rename_all = "snake_case")]
646 enum ReadableExecutionError {
647 InsufficientGas,
648 InvalidGasObject,
649 InvariantViolation,
650 FeatureNotYetSupported,
651 ObjectTooBig {
652 #[serde(with = "crate::_serde::ReadableDisplay")]
653 object_size: u64,
654 #[serde(with = "crate::_serde::ReadableDisplay")]
655 max_object_size: u64,
656 },
657 PackageTooBig {
658 #[serde(with = "crate::_serde::ReadableDisplay")]
659 object_size: u64,
660 #[serde(with = "crate::_serde::ReadableDisplay")]
661 max_object_size: u64,
662 },
663 CircularObjectOwnership {
664 object: ObjectId,
665 },
666 InsufficientCoinBalance,
667 CoinBalanceOverflow,
668 PublishErrorNonZeroAddress,
669 IotaMoveVerificationError,
670 MovePrimitiveRuntimeError {
671 location: Option<MoveLocation>,
672 },
673 MoveAbort {
674 location: MoveLocation,
675 #[serde(with = "crate::_serde::ReadableDisplay")]
676 code: u64,
677 },
678 VmVerificationOrDeserializationError,
679 VmInvariantViolation,
680 FunctionNotFound,
681 ArityMismatch,
682 TypeArityMismatch,
683 NonEntryFunctionInvoked,
684 CommandArgumentError {
685 argument: u16,
686 kind: CommandArgumentError,
687 },
688 TypeArgumentError {
689 type_argument: u16,
690 kind: TypeArgumentError,
691 },
692 UnusedValueWithoutDrop {
693 result: u16,
694 subresult: u16,
695 },
696 InvalidPublicFunctionReturnType {
697 index: u16,
698 },
699 InvalidTransferObject,
700 EffectsTooLarge {
701 #[serde(with = "crate::_serde::ReadableDisplay")]
702 current_size: u64,
703 #[serde(with = "crate::_serde::ReadableDisplay")]
704 max_size: u64,
705 },
706 PublishUpgradeMissingDependency,
707 PublishUpgradeDependencyDowngrade,
708 PackageUpgradeError {
709 kind: PackageUpgradeError,
710 },
711 WrittenObjectsTooLarge {
712 #[serde(with = "crate::_serde::ReadableDisplay")]
713 object_size: u64,
714 #[serde(with = "crate::_serde::ReadableDisplay")]
715 max_object_size: u64,
716 },
717 CertificateDenied,
718 IotaMoveVerificationTimeout,
719 SharedObjectOperationNotAllowed,
720 InputObjectDeleted,
721 ExecutionCancelledDueToSharedObjectCongestion {
722 congested_objects: Vec<ObjectId>,
723 },
724 AddressDeniedForCoin {
725 address: Address,
726 coin_type: String,
727 },
728 CoinTypeGlobalPause {
729 coin_type: String,
730 },
731 ExecutionCancelledDueToRandomnessUnavailable,
732 ExecutionCancelledDueToSharedObjectCongestionV2 {
733 congested_objects: Vec<ObjectId>,
734 suggested_gas_price: u64,
735 },
736 InvalidLinkage,
737 }
738
739 #[derive(serde::Serialize, serde::Deserialize)]
740 enum BinaryExecutionError {
741 InsufficientGas,
742 InvalidGasObject,
743 InvariantViolation,
744 FeatureNotYetSupported,
745 ObjectTooBig {
746 object_size: u64,
747 max_object_size: u64,
748 },
749 PackageTooBig {
750 object_size: u64,
751 max_object_size: u64,
752 },
753 CircularObjectOwnership {
754 object: ObjectId,
755 },
756 InsufficientCoinBalance,
757 CoinBalanceOverflow,
758 PublishErrorNonZeroAddress,
759 IotaMoveVerificationError,
760 MovePrimitiveRuntimeError {
761 location: Option<MoveLocation>,
762 },
763 MoveAbort {
764 location: MoveLocation,
765 code: u64,
766 },
767 VmVerificationOrDeserializationError,
768 VmInvariantViolation,
769 FunctionNotFound,
770 ArityMismatch,
771 TypeArityMismatch,
772 NonEntryFunctionInvoked,
773 CommandArgumentError {
774 argument: u16,
775 kind: CommandArgumentError,
776 },
777 TypeArgumentError {
778 type_argument: u16,
779 kind: TypeArgumentError,
780 },
781 UnusedValueWithoutDrop {
782 result: u16,
783 subresult: u16,
784 },
785 InvalidPublicFunctionReturnType {
786 index: u16,
787 },
788 InvalidTransferObject,
789 EffectsTooLarge {
790 current_size: u64,
791 max_size: u64,
792 },
793 PublishUpgradeMissingDependency,
794 PublishUpgradeDependencyDowngrade,
795 PackageUpgradeError {
796 kind: PackageUpgradeError,
797 },
798 WrittenObjectsTooLarge {
799 object_size: u64,
800 max_object_size: u64,
801 },
802 CertificateDenied,
803 IotaMoveVerificationTimeout,
804 SharedObjectOperationNotAllowed,
805 InputObjectDeleted,
806 ExecutionCancelledDueToSharedObjectCongestion {
807 congested_objects: Vec<ObjectId>,
808 },
809 AddressDeniedForCoin {
810 address: Address,
811 coin_type: String,
812 },
813 CoinTypeGlobalPause {
814 coin_type: String,
815 },
816 ExecutionCancelledDueToRandomnessUnavailable,
817 ExecutionCancelledDueToSharedObjectCongestionV2 {
818 congested_objects: Vec<ObjectId>,
819 suggested_gas_price: u64,
820 },
821 InvalidLinkage,
822 }
823
824 impl Serialize for ExecutionError {
825 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
826 where
827 S: Serializer,
828 {
829 if serializer.is_human_readable() {
830 let readable = match self.clone() {
831 Self::InsufficientGas => ReadableExecutionError::InsufficientGas,
832 Self::InvalidGasObject => ReadableExecutionError::InvalidGasObject,
833 Self::InvariantViolation => ReadableExecutionError::InvariantViolation,
834 Self::FeatureNotYetSupported => ReadableExecutionError::FeatureNotYetSupported,
835 Self::ObjectTooBig {
836 object_size,
837 max_object_size,
838 } => ReadableExecutionError::ObjectTooBig {
839 object_size,
840 max_object_size,
841 },
842 Self::PackageTooBig {
843 object_size,
844 max_object_size,
845 } => ReadableExecutionError::PackageTooBig {
846 object_size,
847 max_object_size,
848 },
849 Self::CircularObjectOwnership { object } => {
850 ReadableExecutionError::CircularObjectOwnership { object }
851 }
852 Self::InsufficientCoinBalance => {
853 ReadableExecutionError::InsufficientCoinBalance
854 }
855 Self::CoinBalanceOverflow => ReadableExecutionError::CoinBalanceOverflow,
856 Self::PublishErrorNonZeroAddress => {
857 ReadableExecutionError::PublishErrorNonZeroAddress
858 }
859 Self::IotaMoveVerificationError => {
860 ReadableExecutionError::IotaMoveVerificationError
861 }
862 Self::MovePrimitiveRuntimeError { location } => {
863 ReadableExecutionError::MovePrimitiveRuntimeError { location }
864 }
865 Self::MoveAbort { location, code } => {
866 ReadableExecutionError::MoveAbort { location, code }
867 }
868 Self::VmVerificationOrDeserializationError => {
869 ReadableExecutionError::VmVerificationOrDeserializationError
870 }
871 Self::VmInvariantViolation => ReadableExecutionError::VmInvariantViolation,
872 Self::FunctionNotFound => ReadableExecutionError::FunctionNotFound,
873 Self::ArityMismatch => ReadableExecutionError::ArityMismatch,
874 Self::TypeArityMismatch => ReadableExecutionError::TypeArityMismatch,
875 Self::NonEntryFunctionInvoked => {
876 ReadableExecutionError::NonEntryFunctionInvoked
877 }
878 Self::CommandArgumentError { argument, kind } => {
879 ReadableExecutionError::CommandArgumentError { argument, kind }
880 }
881 Self::TypeArgumentError {
882 type_argument,
883 kind,
884 } => ReadableExecutionError::TypeArgumentError {
885 type_argument,
886 kind,
887 },
888 Self::UnusedValueWithoutDrop { result, subresult } => {
889 ReadableExecutionError::UnusedValueWithoutDrop { result, subresult }
890 }
891 Self::InvalidPublicFunctionReturnType { index } => {
892 ReadableExecutionError::InvalidPublicFunctionReturnType { index }
893 }
894 Self::InvalidTransferObject => ReadableExecutionError::InvalidTransferObject,
895 Self::EffectsTooLarge {
896 current_size,
897 max_size,
898 } => ReadableExecutionError::EffectsTooLarge {
899 current_size,
900 max_size,
901 },
902 Self::PublishUpgradeMissingDependency => {
903 ReadableExecutionError::PublishUpgradeMissingDependency
904 }
905 Self::PublishUpgradeDependencyDowngrade => {
906 ReadableExecutionError::PublishUpgradeDependencyDowngrade
907 }
908 Self::PackageUpgradeError { kind } => {
909 ReadableExecutionError::PackageUpgradeError { kind }
910 }
911 Self::WrittenObjectsTooLarge {
912 object_size,
913 max_object_size,
914 } => ReadableExecutionError::WrittenObjectsTooLarge {
915 object_size,
916 max_object_size,
917 },
918 Self::CertificateDenied => ReadableExecutionError::CertificateDenied,
919 Self::IotaMoveVerificationTimeout => {
920 ReadableExecutionError::IotaMoveVerificationTimeout
921 }
922 Self::SharedObjectOperationNotAllowed => {
923 ReadableExecutionError::SharedObjectOperationNotAllowed
924 }
925 Self::InputObjectDeleted => ReadableExecutionError::InputObjectDeleted,
926 Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => {
927 ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
928 congested_objects,
929 }
930 }
931 Self::AddressDeniedForCoin { address, coin_type } => {
932 ReadableExecutionError::AddressDeniedForCoin { address, coin_type }
933 }
934 Self::CoinTypeGlobalPause { coin_type } => {
935 ReadableExecutionError::CoinTypeGlobalPause { coin_type }
936 }
937 Self::ExecutionCancelledDueToRandomnessUnavailable => {
938 ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable
939 }
940 Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
941 congested_objects,
942 suggested_gas_price,
943 } => ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
944 congested_objects,
945 suggested_gas_price,
946 },
947 Self::InvalidLinkage => ReadableExecutionError::InvalidLinkage,
948 };
949 readable.serialize(serializer)
950 } else {
951 let binary = match self.clone() {
952 Self::InsufficientGas => BinaryExecutionError::InsufficientGas,
953 Self::InvalidGasObject => BinaryExecutionError::InvalidGasObject,
954 Self::InvariantViolation => BinaryExecutionError::InvariantViolation,
955 Self::FeatureNotYetSupported => BinaryExecutionError::FeatureNotYetSupported,
956 Self::ObjectTooBig {
957 object_size,
958 max_object_size,
959 } => BinaryExecutionError::ObjectTooBig {
960 object_size,
961 max_object_size,
962 },
963 Self::PackageTooBig {
964 object_size,
965 max_object_size,
966 } => BinaryExecutionError::PackageTooBig {
967 object_size,
968 max_object_size,
969 },
970 Self::CircularObjectOwnership { object } => {
971 BinaryExecutionError::CircularObjectOwnership { object }
972 }
973 Self::InsufficientCoinBalance => BinaryExecutionError::InsufficientCoinBalance,
974 Self::CoinBalanceOverflow => BinaryExecutionError::CoinBalanceOverflow,
975 Self::PublishErrorNonZeroAddress => {
976 BinaryExecutionError::PublishErrorNonZeroAddress
977 }
978 Self::IotaMoveVerificationError => {
979 BinaryExecutionError::IotaMoveVerificationError
980 }
981 Self::MovePrimitiveRuntimeError { location } => {
982 BinaryExecutionError::MovePrimitiveRuntimeError { location }
983 }
984 Self::MoveAbort { location, code } => {
985 BinaryExecutionError::MoveAbort { location, code }
986 }
987 Self::VmVerificationOrDeserializationError => {
988 BinaryExecutionError::VmVerificationOrDeserializationError
989 }
990 Self::VmInvariantViolation => BinaryExecutionError::VmInvariantViolation,
991 Self::FunctionNotFound => BinaryExecutionError::FunctionNotFound,
992 Self::ArityMismatch => BinaryExecutionError::ArityMismatch,
993 Self::TypeArityMismatch => BinaryExecutionError::TypeArityMismatch,
994 Self::NonEntryFunctionInvoked => BinaryExecutionError::NonEntryFunctionInvoked,
995 Self::CommandArgumentError { argument, kind } => {
996 BinaryExecutionError::CommandArgumentError { argument, kind }
997 }
998 Self::TypeArgumentError {
999 type_argument,
1000 kind,
1001 } => BinaryExecutionError::TypeArgumentError {
1002 type_argument,
1003 kind,
1004 },
1005 Self::UnusedValueWithoutDrop { result, subresult } => {
1006 BinaryExecutionError::UnusedValueWithoutDrop { result, subresult }
1007 }
1008 Self::InvalidPublicFunctionReturnType { index } => {
1009 BinaryExecutionError::InvalidPublicFunctionReturnType { index }
1010 }
1011 Self::InvalidTransferObject => BinaryExecutionError::InvalidTransferObject,
1012 Self::EffectsTooLarge {
1013 current_size,
1014 max_size,
1015 } => BinaryExecutionError::EffectsTooLarge {
1016 current_size,
1017 max_size,
1018 },
1019 Self::PublishUpgradeMissingDependency => {
1020 BinaryExecutionError::PublishUpgradeMissingDependency
1021 }
1022 Self::PublishUpgradeDependencyDowngrade => {
1023 BinaryExecutionError::PublishUpgradeDependencyDowngrade
1024 }
1025 Self::PackageUpgradeError { kind } => {
1026 BinaryExecutionError::PackageUpgradeError { kind }
1027 }
1028 Self::WrittenObjectsTooLarge {
1029 object_size,
1030 max_object_size,
1031 } => BinaryExecutionError::WrittenObjectsTooLarge {
1032 object_size,
1033 max_object_size,
1034 },
1035 Self::CertificateDenied => BinaryExecutionError::CertificateDenied,
1036 Self::IotaMoveVerificationTimeout => {
1037 BinaryExecutionError::IotaMoveVerificationTimeout
1038 }
1039 Self::SharedObjectOperationNotAllowed => {
1040 BinaryExecutionError::SharedObjectOperationNotAllowed
1041 }
1042 Self::InputObjectDeleted => BinaryExecutionError::InputObjectDeleted,
1043 Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects } => {
1044 BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
1045 congested_objects,
1046 }
1047 }
1048 Self::AddressDeniedForCoin { address, coin_type } => {
1049 BinaryExecutionError::AddressDeniedForCoin { address, coin_type }
1050 }
1051 Self::CoinTypeGlobalPause { coin_type } => {
1052 BinaryExecutionError::CoinTypeGlobalPause { coin_type }
1053 }
1054 Self::ExecutionCancelledDueToRandomnessUnavailable => {
1055 BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable
1056 }
1057 Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
1058 congested_objects,
1059 suggested_gas_price,
1060 } => BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
1061 congested_objects,
1062 suggested_gas_price,
1063 },
1064 Self::InvalidLinkage => BinaryExecutionError::InvalidLinkage,
1065 };
1066 binary.serialize(serializer)
1067 }
1068 }
1069 }
1070
1071 impl<'de> Deserialize<'de> for ExecutionError {
1072 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1073 where
1074 D: Deserializer<'de>,
1075 {
1076 if deserializer.is_human_readable() {
1077 ReadableExecutionError::deserialize(deserializer).map(|readable| match readable {
1078 ReadableExecutionError::InsufficientGas => Self::InsufficientGas,
1079 ReadableExecutionError::InvalidGasObject => Self::InvalidGasObject,
1080 ReadableExecutionError::InvariantViolation => Self::InvariantViolation,
1081 ReadableExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1082 ReadableExecutionError::ObjectTooBig {
1083 object_size,
1084 max_object_size,
1085 } => Self::ObjectTooBig {
1086 object_size,
1087 max_object_size,
1088 },
1089 ReadableExecutionError::PackageTooBig {
1090 object_size,
1091 max_object_size,
1092 } => Self::PackageTooBig {
1093 object_size,
1094 max_object_size,
1095 },
1096 ReadableExecutionError::CircularObjectOwnership { object } => {
1097 Self::CircularObjectOwnership { object }
1098 }
1099 ReadableExecutionError::InsufficientCoinBalance => {
1100 Self::InsufficientCoinBalance
1101 }
1102 ReadableExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1103 ReadableExecutionError::PublishErrorNonZeroAddress => {
1104 Self::PublishErrorNonZeroAddress
1105 }
1106 ReadableExecutionError::IotaMoveVerificationError => {
1107 Self::IotaMoveVerificationError
1108 }
1109 ReadableExecutionError::MovePrimitiveRuntimeError { location } => {
1110 Self::MovePrimitiveRuntimeError { location }
1111 }
1112 ReadableExecutionError::MoveAbort { location, code } => {
1113 Self::MoveAbort { location, code }
1114 }
1115 ReadableExecutionError::VmVerificationOrDeserializationError => {
1116 Self::VmVerificationOrDeserializationError
1117 }
1118 ReadableExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1119 ReadableExecutionError::FunctionNotFound => Self::FunctionNotFound,
1120 ReadableExecutionError::ArityMismatch => Self::ArityMismatch,
1121 ReadableExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1122 ReadableExecutionError::NonEntryFunctionInvoked => {
1123 Self::NonEntryFunctionInvoked
1124 }
1125 ReadableExecutionError::CommandArgumentError { argument, kind } => {
1126 Self::CommandArgumentError { argument, kind }
1127 }
1128 ReadableExecutionError::TypeArgumentError {
1129 type_argument,
1130 kind,
1131 } => Self::TypeArgumentError {
1132 type_argument,
1133 kind,
1134 },
1135 ReadableExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1136 Self::UnusedValueWithoutDrop { result, subresult }
1137 }
1138 ReadableExecutionError::InvalidPublicFunctionReturnType { index } => {
1139 Self::InvalidPublicFunctionReturnType { index }
1140 }
1141 ReadableExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1142 ReadableExecutionError::EffectsTooLarge {
1143 current_size,
1144 max_size,
1145 } => Self::EffectsTooLarge {
1146 current_size,
1147 max_size,
1148 },
1149 ReadableExecutionError::PublishUpgradeMissingDependency => {
1150 Self::PublishUpgradeMissingDependency
1151 }
1152 ReadableExecutionError::PublishUpgradeDependencyDowngrade => {
1153 Self::PublishUpgradeDependencyDowngrade
1154 }
1155 ReadableExecutionError::PackageUpgradeError { kind } => {
1156 Self::PackageUpgradeError { kind }
1157 }
1158 ReadableExecutionError::WrittenObjectsTooLarge {
1159 object_size,
1160 max_object_size,
1161 } => Self::WrittenObjectsTooLarge {
1162 object_size,
1163 max_object_size,
1164 },
1165 ReadableExecutionError::CertificateDenied => Self::CertificateDenied,
1166 ReadableExecutionError::IotaMoveVerificationTimeout => {
1167 Self::IotaMoveVerificationTimeout
1168 }
1169 ReadableExecutionError::SharedObjectOperationNotAllowed => {
1170 Self::SharedObjectOperationNotAllowed
1171 }
1172 ReadableExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1173 ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
1174 congested_objects,
1175 } => Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects },
1176 ReadableExecutionError::AddressDeniedForCoin { address, coin_type } => {
1177 Self::AddressDeniedForCoin { address, coin_type }
1178 }
1179 ReadableExecutionError::CoinTypeGlobalPause { coin_type } => {
1180 Self::CoinTypeGlobalPause { coin_type }
1181 }
1182 ReadableExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
1183 Self::ExecutionCancelledDueToRandomnessUnavailable
1184 }
1185 ReadableExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
1186 congested_objects,
1187 suggested_gas_price,
1188 } => Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
1189 congested_objects,
1190 suggested_gas_price,
1191 },
1192 ReadableExecutionError::InvalidLinkage => Self::InvalidLinkage,
1193 })
1194 } else {
1195 BinaryExecutionError::deserialize(deserializer).map(|binary| match binary {
1196 BinaryExecutionError::InsufficientGas => Self::InsufficientGas,
1197 BinaryExecutionError::InvalidGasObject => Self::InvalidGasObject,
1198 BinaryExecutionError::InvariantViolation => Self::InvariantViolation,
1199 BinaryExecutionError::FeatureNotYetSupported => Self::FeatureNotYetSupported,
1200 BinaryExecutionError::ObjectTooBig {
1201 object_size,
1202 max_object_size,
1203 } => Self::ObjectTooBig {
1204 object_size,
1205 max_object_size,
1206 },
1207 BinaryExecutionError::PackageTooBig {
1208 object_size,
1209 max_object_size,
1210 } => Self::PackageTooBig {
1211 object_size,
1212 max_object_size,
1213 },
1214 BinaryExecutionError::CircularObjectOwnership { object } => {
1215 Self::CircularObjectOwnership { object }
1216 }
1217 BinaryExecutionError::InsufficientCoinBalance => Self::InsufficientCoinBalance,
1218 BinaryExecutionError::CoinBalanceOverflow => Self::CoinBalanceOverflow,
1219 BinaryExecutionError::PublishErrorNonZeroAddress => {
1220 Self::PublishErrorNonZeroAddress
1221 }
1222 BinaryExecutionError::IotaMoveVerificationError => {
1223 Self::IotaMoveVerificationError
1224 }
1225 BinaryExecutionError::MovePrimitiveRuntimeError { location } => {
1226 Self::MovePrimitiveRuntimeError { location }
1227 }
1228 BinaryExecutionError::MoveAbort { location, code } => {
1229 Self::MoveAbort { location, code }
1230 }
1231 BinaryExecutionError::VmVerificationOrDeserializationError => {
1232 Self::VmVerificationOrDeserializationError
1233 }
1234 BinaryExecutionError::VmInvariantViolation => Self::VmInvariantViolation,
1235 BinaryExecutionError::FunctionNotFound => Self::FunctionNotFound,
1236 BinaryExecutionError::ArityMismatch => Self::ArityMismatch,
1237 BinaryExecutionError::TypeArityMismatch => Self::TypeArityMismatch,
1238 BinaryExecutionError::NonEntryFunctionInvoked => Self::NonEntryFunctionInvoked,
1239 BinaryExecutionError::CommandArgumentError { argument, kind } => {
1240 Self::CommandArgumentError { argument, kind }
1241 }
1242 BinaryExecutionError::TypeArgumentError {
1243 type_argument,
1244 kind,
1245 } => Self::TypeArgumentError {
1246 type_argument,
1247 kind,
1248 },
1249 BinaryExecutionError::UnusedValueWithoutDrop { result, subresult } => {
1250 Self::UnusedValueWithoutDrop { result, subresult }
1251 }
1252 BinaryExecutionError::InvalidPublicFunctionReturnType { index } => {
1253 Self::InvalidPublicFunctionReturnType { index }
1254 }
1255 BinaryExecutionError::InvalidTransferObject => Self::InvalidTransferObject,
1256 BinaryExecutionError::EffectsTooLarge {
1257 current_size,
1258 max_size,
1259 } => Self::EffectsTooLarge {
1260 current_size,
1261 max_size,
1262 },
1263 BinaryExecutionError::PublishUpgradeMissingDependency => {
1264 Self::PublishUpgradeMissingDependency
1265 }
1266 BinaryExecutionError::PublishUpgradeDependencyDowngrade => {
1267 Self::PublishUpgradeDependencyDowngrade
1268 }
1269 BinaryExecutionError::PackageUpgradeError { kind } => {
1270 Self::PackageUpgradeError { kind }
1271 }
1272 BinaryExecutionError::WrittenObjectsTooLarge {
1273 object_size,
1274 max_object_size,
1275 } => Self::WrittenObjectsTooLarge {
1276 object_size,
1277 max_object_size,
1278 },
1279 BinaryExecutionError::CertificateDenied => Self::CertificateDenied,
1280 BinaryExecutionError::IotaMoveVerificationTimeout => {
1281 Self::IotaMoveVerificationTimeout
1282 }
1283 BinaryExecutionError::SharedObjectOperationNotAllowed => {
1284 Self::SharedObjectOperationNotAllowed
1285 }
1286 BinaryExecutionError::InputObjectDeleted => Self::InputObjectDeleted,
1287 BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestion {
1288 congested_objects,
1289 } => Self::ExecutionCancelledDueToSharedObjectCongestion { congested_objects },
1290 BinaryExecutionError::AddressDeniedForCoin { address, coin_type } => {
1291 Self::AddressDeniedForCoin { address, coin_type }
1292 }
1293 BinaryExecutionError::CoinTypeGlobalPause { coin_type } => {
1294 Self::CoinTypeGlobalPause { coin_type }
1295 }
1296 BinaryExecutionError::ExecutionCancelledDueToRandomnessUnavailable => {
1297 Self::ExecutionCancelledDueToRandomnessUnavailable
1298 }
1299 BinaryExecutionError::ExecutionCancelledDueToSharedObjectCongestionV2 {
1300 congested_objects,
1301 suggested_gas_price,
1302 } => Self::ExecutionCancelledDueToSharedObjectCongestionV2 {
1303 congested_objects,
1304 suggested_gas_price,
1305 },
1306 BinaryExecutionError::InvalidLinkage => Self::InvalidLinkage,
1307 })
1308 }
1309 }
1310 }
1311
1312 #[derive(serde::Serialize, serde::Deserialize)]
1313 #[serde(tag = "kind", rename_all = "snake_case")]
1314 enum ReadableCommandArgumentError {
1315 TypeMismatch,
1316 InvalidBcsBytes,
1317 InvalidUsageOfPureArgument,
1318 InvalidArgumentToPrivateEntryFunction,
1319 IndexOutOfBounds { index: u16 },
1320 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1321 InvalidResultArity { result: u16 },
1322 InvalidGasCoinUsage,
1323 InvalidValueUsage,
1324 InvalidObjectByValue,
1325 InvalidObjectByMutRef,
1326 SharedObjectOperationNotAllowed,
1327 InvalidArgumentArity,
1328 }
1329
1330 #[derive(serde::Serialize, serde::Deserialize)]
1331 enum BinaryCommandArgumentError {
1332 TypeMismatch,
1333 InvalidBcsBytes,
1334 InvalidUsageOfPureArgument,
1335 InvalidArgumentToPrivateEntryFunction,
1336 IndexOutOfBounds { index: u16 },
1337 SecondaryIndexOutOfBounds { result: u16, subresult: u16 },
1338 InvalidResultArity { result: u16 },
1339 InvalidGasCoinUsage,
1340 InvalidValueUsage,
1341 InvalidObjectByValue,
1342 InvalidObjectByMutRef,
1343 SharedObjectOperationNotAllowed,
1344 InvalidArgumentArity,
1345 }
1346
1347 impl Serialize for CommandArgumentError {
1348 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1349 where
1350 S: Serializer,
1351 {
1352 if serializer.is_human_readable() {
1353 let readable = match self.clone() {
1354 Self::TypeMismatch => ReadableCommandArgumentError::TypeMismatch,
1355 Self::InvalidBcsBytes => ReadableCommandArgumentError::InvalidBcsBytes,
1356 Self::InvalidUsageOfPureArgument => {
1357 ReadableCommandArgumentError::InvalidUsageOfPureArgument
1358 }
1359 Self::InvalidArgumentToPrivateEntryFunction => {
1360 ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1361 }
1362 Self::IndexOutOfBounds { index } => {
1363 ReadableCommandArgumentError::IndexOutOfBounds { index }
1364 }
1365 Self::SecondaryIndexOutOfBounds { result, subresult } => {
1366 ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1367 result,
1368 subresult,
1369 }
1370 }
1371 Self::InvalidResultArity { result } => {
1372 ReadableCommandArgumentError::InvalidResultArity { result }
1373 }
1374 Self::InvalidGasCoinUsage => ReadableCommandArgumentError::InvalidGasCoinUsage,
1375 Self::InvalidValueUsage => ReadableCommandArgumentError::InvalidValueUsage,
1376 Self::InvalidObjectByValue => {
1377 ReadableCommandArgumentError::InvalidObjectByValue
1378 }
1379 Self::InvalidObjectByMutRef => {
1380 ReadableCommandArgumentError::InvalidObjectByMutRef
1381 }
1382 Self::SharedObjectOperationNotAllowed => {
1383 ReadableCommandArgumentError::SharedObjectOperationNotAllowed
1384 }
1385 Self::InvalidArgumentArity => {
1386 ReadableCommandArgumentError::InvalidArgumentArity
1387 }
1388 };
1389 readable.serialize(serializer)
1390 } else {
1391 let binary = match self.clone() {
1392 Self::TypeMismatch => BinaryCommandArgumentError::TypeMismatch,
1393 Self::InvalidBcsBytes => BinaryCommandArgumentError::InvalidBcsBytes,
1394 Self::InvalidUsageOfPureArgument => {
1395 BinaryCommandArgumentError::InvalidUsageOfPureArgument
1396 }
1397 Self::InvalidArgumentToPrivateEntryFunction => {
1398 BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction
1399 }
1400 Self::IndexOutOfBounds { index } => {
1401 BinaryCommandArgumentError::IndexOutOfBounds { index }
1402 }
1403 Self::SecondaryIndexOutOfBounds { result, subresult } => {
1404 BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult }
1405 }
1406 Self::InvalidResultArity { result } => {
1407 BinaryCommandArgumentError::InvalidResultArity { result }
1408 }
1409 Self::InvalidGasCoinUsage => BinaryCommandArgumentError::InvalidGasCoinUsage,
1410 Self::InvalidValueUsage => BinaryCommandArgumentError::InvalidValueUsage,
1411 Self::InvalidObjectByValue => BinaryCommandArgumentError::InvalidObjectByValue,
1412 Self::InvalidObjectByMutRef => {
1413 BinaryCommandArgumentError::InvalidObjectByMutRef
1414 }
1415 Self::SharedObjectOperationNotAllowed => {
1416 BinaryCommandArgumentError::SharedObjectOperationNotAllowed
1417 }
1418 Self::InvalidArgumentArity => BinaryCommandArgumentError::InvalidArgumentArity,
1419 };
1420 binary.serialize(serializer)
1421 }
1422 }
1423 }
1424
1425 impl<'de> Deserialize<'de> for CommandArgumentError {
1426 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1427 where
1428 D: Deserializer<'de>,
1429 {
1430 if deserializer.is_human_readable() {
1431 ReadableCommandArgumentError::deserialize(deserializer).map(|readable| {
1432 match readable {
1433 ReadableCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1434 ReadableCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1435 ReadableCommandArgumentError::InvalidUsageOfPureArgument => {
1436 Self::InvalidUsageOfPureArgument
1437 }
1438 ReadableCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1439 Self::InvalidArgumentToPrivateEntryFunction
1440 }
1441 ReadableCommandArgumentError::IndexOutOfBounds { index } => {
1442 Self::IndexOutOfBounds { index }
1443 }
1444 ReadableCommandArgumentError::SecondaryIndexOutOfBounds {
1445 result,
1446 subresult,
1447 } => Self::SecondaryIndexOutOfBounds { result, subresult },
1448 ReadableCommandArgumentError::InvalidResultArity { result } => {
1449 Self::InvalidResultArity { result }
1450 }
1451 ReadableCommandArgumentError::InvalidGasCoinUsage => {
1452 Self::InvalidGasCoinUsage
1453 }
1454 ReadableCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1455 ReadableCommandArgumentError::InvalidObjectByValue => {
1456 Self::InvalidObjectByValue
1457 }
1458 ReadableCommandArgumentError::InvalidObjectByMutRef => {
1459 Self::InvalidObjectByMutRef
1460 }
1461 ReadableCommandArgumentError::SharedObjectOperationNotAllowed => {
1462 Self::SharedObjectOperationNotAllowed
1463 }
1464 ReadableCommandArgumentError::InvalidArgumentArity => {
1465 Self::InvalidArgumentArity
1466 }
1467 }
1468 })
1469 } else {
1470 BinaryCommandArgumentError::deserialize(deserializer).map(|binary| match binary {
1471 BinaryCommandArgumentError::TypeMismatch => Self::TypeMismatch,
1472 BinaryCommandArgumentError::InvalidBcsBytes => Self::InvalidBcsBytes,
1473 BinaryCommandArgumentError::InvalidUsageOfPureArgument => {
1474 Self::InvalidUsageOfPureArgument
1475 }
1476 BinaryCommandArgumentError::InvalidArgumentToPrivateEntryFunction => {
1477 Self::InvalidArgumentToPrivateEntryFunction
1478 }
1479 BinaryCommandArgumentError::IndexOutOfBounds { index } => {
1480 Self::IndexOutOfBounds { index }
1481 }
1482 BinaryCommandArgumentError::SecondaryIndexOutOfBounds { result, subresult } => {
1483 Self::SecondaryIndexOutOfBounds { result, subresult }
1484 }
1485 BinaryCommandArgumentError::InvalidResultArity { result } => {
1486 Self::InvalidResultArity { result }
1487 }
1488 BinaryCommandArgumentError::InvalidGasCoinUsage => Self::InvalidGasCoinUsage,
1489 BinaryCommandArgumentError::InvalidValueUsage => Self::InvalidValueUsage,
1490 BinaryCommandArgumentError::InvalidObjectByValue => Self::InvalidObjectByValue,
1491 BinaryCommandArgumentError::InvalidObjectByMutRef => {
1492 Self::InvalidObjectByMutRef
1493 }
1494 BinaryCommandArgumentError::SharedObjectOperationNotAllowed => {
1495 Self::SharedObjectOperationNotAllowed
1496 }
1497 BinaryCommandArgumentError::InvalidArgumentArity => Self::InvalidArgumentArity,
1498 })
1499 }
1500 }
1501 }
1502
1503 #[derive(serde::Serialize, serde::Deserialize)]
1504 #[serde(tag = "kind", rename_all = "snake_case")]
1505 enum ReadablePackageUpgradeError {
1506 UnableToFetchPackage {
1507 package_id: ObjectId,
1508 },
1509 NotAPackage {
1510 object_id: ObjectId,
1511 },
1512 IncompatibleUpgrade,
1513 DigestDoesNotMatch {
1514 digest: Digest,
1515 },
1516 UnknownUpgradePolicy {
1517 policy: u8,
1518 },
1519 PackageIdDoesNotMatch {
1520 package_id: ObjectId,
1521 ticket_id: ObjectId,
1522 },
1523 }
1524
1525 #[derive(serde::Serialize, serde::Deserialize)]
1526 enum BinaryPackageUpgradeError {
1527 UnableToFetchPackage {
1528 package_id: ObjectId,
1529 },
1530 NotAPackage {
1531 object_id: ObjectId,
1532 },
1533 IncompatibleUpgrade,
1534 DigestDoesNotMatch {
1535 digest: Digest,
1536 },
1537 UnknownUpgradePolicy {
1538 policy: u8,
1539 },
1540 PackageIdDoesNotMatch {
1541 package_id: ObjectId,
1542 ticket_id: ObjectId,
1543 },
1544 }
1545
1546 impl Serialize for PackageUpgradeError {
1547 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1548 where
1549 S: Serializer,
1550 {
1551 if serializer.is_human_readable() {
1552 let readable = match self.clone() {
1553 Self::UnableToFetchPackage { package_id } => {
1554 ReadablePackageUpgradeError::UnableToFetchPackage { package_id }
1555 }
1556 Self::NotAPackage { object_id } => {
1557 ReadablePackageUpgradeError::NotAPackage { object_id }
1558 }
1559 Self::IncompatibleUpgrade => ReadablePackageUpgradeError::IncompatibleUpgrade,
1560 Self::DigestDoesNotMatch { digest } => {
1561 ReadablePackageUpgradeError::DigestDoesNotMatch { digest }
1562 }
1563 Self::UnknownUpgradePolicy { policy } => {
1564 ReadablePackageUpgradeError::UnknownUpgradePolicy { policy }
1565 }
1566 Self::PackageIdDoesNotMatch {
1567 package_id,
1568 ticket_id,
1569 } => ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1570 package_id,
1571 ticket_id,
1572 },
1573 };
1574 readable.serialize(serializer)
1575 } else {
1576 let binary = match self.clone() {
1577 Self::UnableToFetchPackage { package_id } => {
1578 BinaryPackageUpgradeError::UnableToFetchPackage { package_id }
1579 }
1580 Self::NotAPackage { object_id } => {
1581 BinaryPackageUpgradeError::NotAPackage { object_id }
1582 }
1583 Self::IncompatibleUpgrade => BinaryPackageUpgradeError::IncompatibleUpgrade,
1584 Self::DigestDoesNotMatch { digest } => {
1585 BinaryPackageUpgradeError::DigestDoesNotMatch { digest }
1586 }
1587 Self::UnknownUpgradePolicy { policy } => {
1588 BinaryPackageUpgradeError::UnknownUpgradePolicy { policy }
1589 }
1590 Self::PackageIdDoesNotMatch {
1591 package_id,
1592 ticket_id,
1593 } => BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1594 package_id,
1595 ticket_id,
1596 },
1597 };
1598 binary.serialize(serializer)
1599 }
1600 }
1601 }
1602
1603 impl<'de> Deserialize<'de> for PackageUpgradeError {
1604 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
1605 where
1606 D: Deserializer<'de>,
1607 {
1608 if deserializer.is_human_readable() {
1609 ReadablePackageUpgradeError::deserialize(deserializer).map(
1610 |readable| match readable {
1611 ReadablePackageUpgradeError::UnableToFetchPackage { package_id } => {
1612 Self::UnableToFetchPackage { package_id }
1613 }
1614 ReadablePackageUpgradeError::NotAPackage { object_id } => {
1615 Self::NotAPackage { object_id }
1616 }
1617 ReadablePackageUpgradeError::IncompatibleUpgrade => {
1618 Self::IncompatibleUpgrade
1619 }
1620 ReadablePackageUpgradeError::DigestDoesNotMatch { digest } => {
1621 Self::DigestDoesNotMatch { digest }
1622 }
1623 ReadablePackageUpgradeError::UnknownUpgradePolicy { policy } => {
1624 Self::UnknownUpgradePolicy { policy }
1625 }
1626 ReadablePackageUpgradeError::PackageIdDoesNotMatch {
1627 package_id,
1628 ticket_id,
1629 } => Self::PackageIdDoesNotMatch {
1630 package_id,
1631 ticket_id,
1632 },
1633 },
1634 )
1635 } else {
1636 BinaryPackageUpgradeError::deserialize(deserializer).map(|binary| match binary {
1637 BinaryPackageUpgradeError::UnableToFetchPackage { package_id } => {
1638 Self::UnableToFetchPackage { package_id }
1639 }
1640 BinaryPackageUpgradeError::NotAPackage { object_id } => {
1641 Self::NotAPackage { object_id }
1642 }
1643 BinaryPackageUpgradeError::IncompatibleUpgrade => Self::IncompatibleUpgrade,
1644 BinaryPackageUpgradeError::DigestDoesNotMatch { digest } => {
1645 Self::DigestDoesNotMatch { digest }
1646 }
1647 BinaryPackageUpgradeError::UnknownUpgradePolicy { policy } => {
1648 Self::UnknownUpgradePolicy { policy }
1649 }
1650 BinaryPackageUpgradeError::PackageIdDoesNotMatch {
1651 package_id,
1652 ticket_id,
1653 } => Self::PackageIdDoesNotMatch {
1654 package_id,
1655 ticket_id,
1656 },
1657 })
1658 }
1659 }
1660 }
1661}