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
use std::fmt;
pub use crate::error::{Error, ErrorContext, Result};
pub use crate::host::log;
#[derive(Debug)]
pub(crate) enum ModuleError {
DuplicateRegistration(String),
}
impl fmt::Display for ModuleError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ModuleError::*;
match self {
DuplicateRegistration(name) => write!(
f,
"WebAssembly module attempted to register 2 different extensions under the same `root_id` \"{}\"",
name,
),
}
}
}
impl std::error::Error for ModuleError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
#[derive(Debug)]
pub(crate) enum ConfigurationError {
UnknownExtension {
requested: String,
available: Vec<String>,
},
}
impl fmt::Display for ConfigurationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ConfigurationError::*;
match self {
UnknownExtension { requested, available } => write!(
f,
"WebAssembly module has no extension with `root_id` \"{}\"; valid `root_id` values are: {:?}",
requested, available
),
}
}
}
impl std::error::Error for ConfigurationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
None
}
}
pub(crate) trait ErrorSink {
fn observe(&self, context: &str, err: &Error);
}
impl dyn ErrorSink {
pub fn default() -> &'static dyn ErrorSink {
&impls::DefaultErrorSink
}
}
mod impls {
use super::{Error, ErrorSink};
use crate::host::log;
pub(super) struct DefaultErrorSink;
impl ErrorSink for DefaultErrorSink {
fn observe(&self, context: &str, err: &Error) {
log::error!("{}: {}", context, err);
}
}
}