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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::io::Error as IOError;

#[derive(Debug, thiserror::Error)]
#[allow(clippy::large_enum_variant)]
pub enum Error {
    /************************************************************/
    // API caller errors (e.g. doing things in wrong order)
    /************************************************************/
    #[error("suibase: Not installed. Need to run ~/suibase/install")]
    NotInstalled,

    #[error("suibase: Workdir not selected. Successful call to `select_workdir` needed")]
    WorkdirNotSelected,

    #[error(
        "suibase: Path could not be access. Check suibase is selecting a valid active workdir"
    )]
    WorkdirAccessError,

    #[error("suibase: Workdir does not exists. Check suibase is selecting a valid active workdir")]
    WorkdirNotExists,

    #[error("suibase: Not finding keystore `{path:?}`. Run the sui client to create it?")]
    SuibaseKeystoreNotExists { path: String },

    #[error(
        "suibase: No published data found for package `{package_name:?}`.\n\
        Note that the package must have been published via `{workdir:?} publish`, and not e.g. the Sui SDK."
        )
    ]
    PublishedDataNotFound {
        package_name: String,
        workdir: String,
        path: String,
    },

    #[error("suibase: Missing link definition. Check suibase.yaml links section.")]
    MissingLinkDefinition,

    #[error("suibase: Missing at least one link definition. Check suibase.yaml links section.")]
    MissingAtLeastOneLinkDefinition,

    #[error("suibase: Missing `{url_field:?}` link field. May be a problem with the suibase.yaml link section (1).")]
    MissingLinkField { url_field: String },

    #[error("suibase: Missing config.yaml. Did you do '{workdir:?} start'?")]
    ConfigAccessError { workdir: String },

    #[error("suibase: Access problem with config.yaml. Did you do '{workdir:?} start' or run the sui client once?")]
    ConfigReadError { workdir: String },

    #[error("suibase: Unknown active address. Did you run the sui client at least once?")]
    ConfigActiveAddressParseError { address: String },

    /*****************************/
    // API bad parameter errors.
    /*****************************/
    #[error("suibase: Invalid workdir name (empty string)")]
    WorkdirNameEmpty,

    #[error("suibase: Invalid package name (empty string)")]
    PackageNameEmpty,

    #[error("suibase: Invalid address name (empty string)")]
    AddressNameEmpty,

    #[error("suibase: Invalid object_type parameter with missing field")]
    ObjectTypeMissingField,

    #[error("suibase: Invalid object_type parameter")]
    ObjectTypeInvalidFormat,

    #[error("suibase: Not finding address name'{address_name:?}'")]
    AddressNameNotFound { address_name: String },

    /*****************************/
    // Suibase filesystem related errors
    //
    // Should not normally happen. Relates to files generated by suibase, so could
    // be either a bug or abnormal termination while the file was being written.
    /*****************************/
    #[error("suibase: Active workdir read of .state/name failed. Try to 'update' the workdir")]
    WorkdirStateNameAccessFailed,

    #[error(
        "suibase: Could not open DNS (client address) file `{path:?}`. Try to 'update' the workdir"
    )]
    WorkdirStateDNSAccessFailed { path: String },

    #[error("suibase: Active workdir .state/name not set. Try to 'update' the workdir")]
    WorkdirStateNameNotSet,

    #[error("suibase: Invalid package-id.json format")]
    PackageIdJsonInvalidFormat,

    #[error("suibase: Invalid package id hexadecimal `{id:?}`.")]
    PackageIdInvalidHex { id: String },

    #[error("suibase: Could not read published new objects file `{path:?}`")]
    PublishedNewObjectReadError { path: String },

    #[error("suibase: Could not parse published new objects id `{id:?}` from file `{path:?}`")]
    PublishedNewObjectParseError { path: String, id: String },

    #[error(
        "suibase: Workdir not fully initialized. Do '{workdir:?} start' or '{workdir:?} update'"
    )]
    WorkdirInitializationIncomplete { workdir: String },

    #[error("suibase: Could not read dns file `{path:?}`")]
    WorkdirStateDNSReadError { path: String },

    #[error("suibase: Could not parse dns address `{address:?}` from file `{path:?}`")]
    WorkdirStateDNSParseError { path: String, address: String },

    #[error(
        "suibase: [code:1] Could not open published data `{path:?}`.\n\
        IO Error: {io_error:?}\
        Was the package `{package_name:?}` published with success?",
        )
    ]
    PublishedDataAccessError { package_name: String, path: String, io_error: IOError },

    #[error("suibase: [code:2] Could not open published data `{path:?}`. Symlink value is `{symlink_target:?}`. Was the package `{package_name:?}` published with success?")]
    PublishedDataAccessErrorInvalidSymlink {
        package_name: String,
        path: String,
        symlink_target: String,
    },

    #[error("suibase: [code:3] Could not open published data `{path:?}`. Was the package `{package_name:?}` published with success?")]
    PublishedDataAccessErrorSymlinkNotFound { package_name: String, path: String },

    #[error("suibase: Could not open published new objects file `{path:?}`. Was the package published with success?")]
    PublishedNewObjectAccessError { path: String },

    #[error("suibase: Could not read link file `{path:?}`")]
    WorkdirStateLinkReadError { path: String },

    /*****************************/
    // Suibase internal errors
    // Likely a bug in  code.
    /*****************************/
    #[error("suibase: Workdir name not set. Internal error. Contact developer")]
    WorkdirNameNotSet,

    #[error("suibase: Workdir path not set. Internal error. Contact developer")]
    WorkdirPathNotSet,

    #[error("suibase: Invalid file name (empty string)")]
    FileNameEmpty,

    #[error("suibase: Invalid state name (empty string)")]
    StateNameEmpty,
}