Skip to content

Commit

Permalink
chore: Improve no instantiation error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Apr 4, 2024
1 parent 5888a88 commit bc15684
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 3 deletions.
112 changes: 110 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion sylvia-derive/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ impl<'a> StructMessage<'a> {
method
} else {
if ty == MsgType::Instantiate {
emit_error!(source.span(), "No instantiation message");
emit_error!(
source.span(), "Missing instantiation message.";
note = source.span() => "`sylvia::contract` requires exactly one method marked with `#[sv::msg(instantiation)]` attribute."

Check warning on line 99 in sylvia-derive/src/message.rs

View check run for this annotation

Codecov / codecov/patch

sylvia-derive/src/message.rs#L97-L99

Added lines #L97 - L99 were not covered by tests
);
}
return None;
};
Expand Down
1 change: 1 addition & 0 deletions sylvia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ cw-multi-test = { workspace = true }
cw-storage-plus = { workspace = true }
cw-utils = { workspace = true }
thiserror = { workspace = true }
trybuild = "1.0.91"

[package.metadata.docs.rs]
all-features = true
Expand Down
5 changes: 5 additions & 0 deletions sylvia/tests/ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.compile_fail("tests/ui/**/*.rs");
}
10 changes: 10 additions & 0 deletions sylvia/tests/ui/missing_method/instantiation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pub struct Contract {}

#[sylvia::contract]
impl Contract {
pub const fn new() -> Self {
Self {}
}
}

fn main() {}
8 changes: 8 additions & 0 deletions sylvia/tests/ui/missing_method/instantiation.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: Missing instantiation message.

= note: `sylvia::contract` requires exactly one method marked with `#[sv::msg(instantiation)]` attribute.

--> tests/ui/missing_method/instantiation.rs:4:1
|
4 | impl Contract {
| ^^^^

0 comments on commit bc15684

Please sign in to comment.