Skip to content

Commit fb41b99

Browse files
committed
Don't return unnecessary diagnostics from macros
1 parent 0ed3629 commit fb41b99

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

crates/snforge-scarb-plugin/src/derives/fuzzable.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ pub fn fuzzable_derive(item: &TokenStream) -> ProcMacroResult {
1515
let db = SimpleParserDatabase::default();
1616
let (parsed, diagnostics) = db.parse_token_stream(item);
1717

18-
if !diagnostics.is_empty() {
19-
return ProcMacroResult::new(TokenStream::empty())
20-
.with_diagnostics(Diagnostic::error("Failed because of invalid syntax").into());
18+
if diagnostics.check_error_free().is_err() {
19+
return ProcMacroResult::new(TokenStream::empty());
2120
}
2221

2322
let syntax_db = db.upcast();

crates/snforge-scarb-plugin/src/parse.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ use cairo_lang_utils::Upcast;
1212

1313
pub fn parse<T: AttributeInfo>(
1414
code: &TokenStream,
15-
) -> Result<(SimpleParserDatabase, FunctionWithBody), Diagnostic> {
15+
) -> Result<(SimpleParserDatabase, FunctionWithBody), Vec<Diagnostic>> {
1616
let simple_db = SimpleParserDatabase::default();
1717
let (parsed_node, diagnostics) = simple_db.parse_token_stream(code);
1818

19-
if !diagnostics.is_empty() {
20-
return Err(Diagnostic::error("Failed because of invalid syntax"));
19+
if diagnostics.check_error_free().is_err() {
20+
return Err(vec![]);
2121
}
2222

2323
let db = simple_db.upcast();
@@ -34,7 +34,7 @@ pub fn parse<T: AttributeInfo>(
3434

3535
match function {
3636
Some(func) => Ok((simple_db, func)),
37-
None => Err(T::error("can be used only on a function")),
37+
None => Err(vec![T::error("can be used only on a function")]),
3838
}
3939
}
4040

0 commit comments

Comments
 (0)