Skip to content

Commit edd161e

Browse files
committed
Slightly improve error messages.
1 parent 4371a22 commit edd161e

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

crates/wac-parser/src/resolution.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,25 +682,27 @@ pub enum Error {
682682
span: SourceSpan,
683683
},
684684
/// An import is not in the target world.
685-
#[error("import `{name}` is not present in target world `{world}`")]
685+
#[error("target world `{world}` does not have an import named `{name}`")]
686686
ImportNotInTarget {
687687
/// The import name.
688688
name: String,
689689
/// The target world.
690690
world: String,
691691
/// The span where the error occurred.
692-
#[label(primary, "import `{name}` is not in the target world")]
692+
#[label(primary, "cannot have an import named `{name}`")]
693693
span: SourceSpan,
694694
},
695695
/// Missing an export for the target world.
696-
#[error("missing export `{name}` for target world `{world}`")]
696+
#[error("target world `{world}` requires an export named `{name}`")]
697697
MissingTargetExport {
698698
/// The export name.
699699
name: String,
700+
/// The expected item kind.
701+
kind: String,
700702
/// The target world.
701703
world: String,
702704
/// The span where the error occurred.
703-
#[label(primary, "must export `{name}` to target this world")]
705+
#[label(primary, "must export a {kind} named `{name}` to target this world")]
704706
span: SourceSpan,
705707
},
706708
/// An import or export has a mismatched type for the target world.

crates/wac-parser/src/resolution/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,6 +2305,7 @@ impl<'a> AstResolver<'a> {
23052305
.ok_or_else(|| Error::MissingTargetExport {
23062306
name: name.clone(),
23072307
world: path.string.to_owned(),
2308+
kind: expected.as_str(&self.definitions).to_string(),
23082309
span: path.span,
23092310
})?;
23102311

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
failed to resolve document
22

3-
× missing export `hello` for target world `foo:bar/baz`
3+
× target world `foo:bar/baz` requires an export named `hello`
44
╭─[tests/resolution/fail/missing-target-export.wac:1:27]
55
1 │ package test:comp targets foo:bar/baz;
66
· ─────┬─────
7-
· ╰── must export `hello` to target this world
7+
· ╰── must export a function named `hello` to target this world
88
╰────
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
failed to resolve document
22

3-
× import `bar` is not present in target world `test:comp/foo`
3+
× target world `test:comp/foo` does not have an import named `bar`
44
╭─[tests/resolution/fail/target-extraneous-import.wac:7:8]
55
6 │
66
7 │ import bar: func();
77
· ─┬─
8-
· ╰── import `bar` is not in the target world
8+
· ╰── cannot have an import named `bar`
99
╰────

0 commit comments

Comments
 (0)