1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) Mysten Labs, Inc.
// Modifications Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::sync::Arc;

use iota_types::TypeTag;
use move_binary_format::errors::VMError;
use move_core_types::account_address::AccountAddress;
use thiserror::Error;

#[derive(Error, Debug, Clone)]
pub enum Error {
    #[error("{0}")]
    Bcs(#[from] bcs::Error),

    #[error("Store {} error: {}", store, source)]
    Store {
        store: &'static str,
        source: Arc<dyn std::error::Error + Send + Sync + 'static>,
    },

    #[error("{0}")]
    Deserialize(VMError),

    #[error("Package has no modules: {0}")]
    EmptyPackage(AccountAddress),

    #[error("Function not found: {0}::{1}::{2}")]
    FunctionNotFound(AccountAddress, String, String),

    #[error(
        "Conflicting types for input {0}: {} and {}",
        .1.to_canonical_display(/* with_prefix */ true),
        .2.to_canonical_display(/* with_prefix */ true),
    )]
    InputTypeConflict(u16, TypeTag, TypeTag),

    #[error("Linkage not found for package: {0}")]
    LinkageNotFound(AccountAddress),

    #[error("Module not found: {0}::{1}")]
    ModuleNotFound(AccountAddress, String),

    #[error("No origin package found for {0}::{1}::{2}")]
    NoTypeOrigin(AccountAddress, String, String),

    #[error("Not a package: {0}")]
    NotAPackage(AccountAddress),

    #[error("Not an identifier: '{0}'")]
    NotAnIdentifier(String),

    #[error("Package not found: {0}")]
    PackageNotFound(AccountAddress),

    #[error("Datatype not found: {0}::{1}::{2}")]
    DatatypeNotFound(AccountAddress, String, String),

    #[error("More than {0} struct definitions required to resolve type")]
    TooManyTypeNodes(usize, usize),

    #[error("Expected at most {0} type parameters, got {1}")]
    TooManyTypeParams(usize, usize),

    #[error("Expected {0} type parameters, but got {1}")]
    TypeArityMismatch(usize, usize),

    #[error("Type parameter nesting exceeded limit of {0}")]
    TypeParamNesting(usize, usize),

    #[error("Type Parameter {0} out of bounds ({1})")]
    TypeParamOOB(u16, usize),

    #[error("Unexpected reference type.")]
    UnexpectedReference,

    #[error("Unexpected type: 'signer'.")]
    UnexpectedSigner,

    #[error("Unexpected error: {0}")]
    Unexpected(Arc<dyn std::error::Error + Send + Sync + 'static>),

    #[error("Type layout nesting exceeded limit of {0}")]
    ValueNesting(usize),
}