Skip to content

Commit a38b928

Browse files
authored
Add additional error context to ComponentEncoder::encode (#1474)
* Add additional error context to ComponentEncoder::encode Signed-off-by: Ryan Levick <ryan.levick@fermyon.com> * Update tests Signed-off-by: Ryan Levick <ryan.levick@fermyon.com> --------- Signed-off-by: Ryan Levick <ryan.levick@fermyon.com>
1 parent e048db7 commit a38b928

13 files changed

Lines changed: 55 additions & 16 deletions

File tree

crates/wit-component/src/encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ impl ComponentEncoder {
20782078
bail!("a module is required when encoding a component");
20792079
}
20802080

2081-
let world = ComponentWorld::new(self)?;
2081+
let world = ComponentWorld::new(self).context("failed to decode world from module")?;
20822082
let mut state = EncodingState {
20832083
component: ComponentBuilder::default(),
20842084
module_index: None,

crates/wit-component/src/encoding/world.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ impl<'a> ComponentWorld<'a> {
7676
&encoder.metadata,
7777
&encoder.main_module_exports,
7878
&adapters,
79-
)?;
79+
)
80+
.context("module was not valid")?;
8081

8182
let mut ret = ComponentWorld {
8283
encoder,
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
no top-level imported function `foo` specified
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: no top-level imported function `foo` specified
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
failed to validate exported interface `foo`
1+
failed to decode world from module
22

33
Caused by:
4-
type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
4+
0: module was not valid
5+
1: failed to validate exported interface `foo`
6+
2: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
no top-level imported function `[resource-rep]a` specified
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: no top-level imported function `[resource-rep]a` specified
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
type mismatch for function `[resource-drop]a`: expected `[I32] -> []` but found `[I32] -> [I32]`
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: type mismatch for function `[resource-drop]a`: expected `[I32] -> []` but found `[I32] -> [I32]`
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
failed to validate import interface `foo`
1+
failed to decode world from module
22

33
Caused by:
4-
type mismatch for function `bar`: expected `[I32, I32] -> []` but found `[] -> []`
4+
0: module was not valid
5+
1: failed to validate import interface `foo`
6+
2: type mismatch for function `bar`: expected `[I32, I32] -> []` but found `[] -> []`
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
module is only allowed to import functions
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: module is only allowed to import functions
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
module does not export required function `a`
1+
failed to decode world from module
2+
3+
Caused by:
4+
0: module was not valid
5+
1: module does not export required function `a`

0 commit comments

Comments
 (0)