fce_wit_interfaces/
errors.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use std::error::Error;
18
19#[derive(Debug)]
20pub enum FCEWITInterfacesError {
21    /// WIT doesn't contain such type.
22    NoSuchType(u32),
23
24    /// WIT doesn't contain such export.
25    NoSuchExport(u32),
26
27    /// WIT doesn't contain such import.
28    NoSuchImport(u32),
29
30    /// WIT doesn't contain such import.
31    NoSuchAdapter(u32),
32}
33
34impl Error for FCEWITInterfacesError {}
35
36impl std::fmt::Display for FCEWITInterfacesError {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
38        match self {
39            FCEWITInterfacesError::NoSuchType(type_id) => write!(
40                f,
41                "Loaded module doesn't contain type with idx = {}",
42                type_id
43            ),
44            FCEWITInterfacesError::NoSuchExport(export_type_id) => write!(
45                f,
46                "Loaded module doesn't contain export with type idx = {}",
47                export_type_id
48            ),
49            FCEWITInterfacesError::NoSuchImport(import_type_id) => write!(
50                f,
51                "Loaded module doesn't contain import with type idx = {}",
52                import_type_id
53            ),
54            FCEWITInterfacesError::NoSuchAdapter(adapter_type_id) => write!(
55                f,
56                "Loaded module doesn't contain adapter with type idx = {}",
57                adapter_type_id
58            ),
59        }
60    }
61}