1
1
use crate :: lib:: std:: string:: String ;
2
+ #[ cfg( feature = "std" ) ]
2
3
use thiserror:: Error ;
3
4
4
5
// Compilation Errors
6
+ //
7
+ // If `std` feature is enable, we can't use `thiserror` until
8
+ // https://github.com/dtolnay/thiserror/pull/64 is merged.
5
9
6
10
/// The WebAssembly.CompileError object indicates an error during
7
11
/// WebAssembly decoding or validation.
8
12
///
9
13
/// This is based on the [Wasm Compile Error][compile-error] API.
10
14
///
11
15
/// [compiler-error]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError
12
- #[ derive( Error , Debug ) ]
16
+ #[ derive( Debug ) ]
17
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
13
18
pub enum CompileError {
14
19
/// A Wasm translation error occured.
15
- #[ error( "WebAssembly translation error: {0}" ) ]
16
- Wasm ( #[ from] WasmError ) ,
20
+ #[ cfg_attr ( feature = "std" , error( "WebAssembly translation error: {0}" ) ) ]
21
+ Wasm ( #[ cfg_attr ( feature = "std" , from) ] WasmError ) ,
17
22
18
23
/// A compilation error occured.
19
- #[ error( "Compilation error: {0}" ) ]
24
+ #[ cfg_attr ( feature = "std" , error( "Compilation error: {0}" ) ) ]
20
25
Codegen ( String ) ,
21
26
22
27
/// The module did not pass validation.
23
- #[ error( "Validation error: {0}" ) ]
28
+ #[ cfg_attr ( feature = "std" , error( "Validation error: {0}" ) ) ]
24
29
Validate ( String ) ,
25
30
26
31
/// The compiler doesn't support a Wasm feature
27
- #[ error( "Feature {0} is not yet supported" ) ]
32
+ #[ cfg_attr ( feature = "std" , error( "Feature {0} is not yet supported" ) ) ]
28
33
UnsupportedFeature ( String ) ,
29
34
30
35
/// Insufficient resources available for execution.
31
- #[ error( "Insufficient resources: {0}" ) ]
36
+ #[ cfg_attr ( feature = "std" , error( "Insufficient resources: {0}" ) ) ]
32
37
Resource ( String ) ,
33
38
}
34
39
35
40
/// A WebAssembly translation error.
36
41
///
37
42
/// When a WebAssembly function can't be translated, one of these error codes will be returned
38
43
/// to describe the failure.
39
- #[ derive( Error , Debug ) ]
44
+ #[ derive( Debug ) ]
45
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
40
46
pub enum WasmError {
41
47
/// The input WebAssembly code is invalid.
42
48
///
43
49
/// This error code is used by a WebAssembly translator when it encounters invalid WebAssembly
44
50
/// code. This should never happen for validated WebAssembly code.
45
- #[ error( "Invalid input WebAssembly code at offset {offset}: {message}" ) ]
51
+ #[ cfg_attr(
52
+ feature = "std" ,
53
+ error( "Invalid input WebAssembly code at offset {offset}: {message}" )
54
+ ) ]
46
55
InvalidWebAssembly {
47
56
/// A string describing the validation error.
48
57
message : String ,
@@ -53,17 +62,27 @@ pub enum WasmError {
53
62
/// A feature used by the WebAssembly code is not supported by the embedding environment.
54
63
///
55
64
/// Embedding environments may have their own limitations and feature restrictions.
56
- #[ error( "Unsupported feature: {0}" ) ]
65
+ #[ cfg_attr ( feature = "std" , error( "Unsupported feature: {0}" ) ) ]
57
66
Unsupported ( String ) ,
58
67
59
68
/// An implementation limit was exceeded.
60
- #[ error( "Implementation limit exceeded" ) ]
69
+ #[ cfg_attr ( feature = "std" , error( "Implementation limit exceeded" ) ) ]
61
70
ImplLimitExceeded ,
62
71
63
72
/// A generic error.
64
- #[ error( "{0}" ) ]
73
+ #[ cfg_attr ( feature = "std" , error( "{0}" ) ) ]
65
74
Generic ( String ) ,
66
75
}
67
76
77
+ /// The error that can happen while parsing a `str`
78
+ /// to retrieve a [`CpuFeature`].
79
+ #[ derive( Debug ) ]
80
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
81
+ pub enum ParseCpuFeatureError {
82
+ /// The provided string feature doesn't exist
83
+ #[ cfg_attr( feature = "std" , error( "CpuFeature {0} not recognized" ) ) ]
84
+ Missing ( String ) ,
85
+ }
86
+
68
87
/// A convenient alias for a `Result` that uses `WasmError` as the error type.
69
88
pub type WasmResult < T > = Result < T , WasmError > ;
0 commit comments