Skip to content

Commit 3afd82e

Browse files
authored
chore: Added Custom error when using init on SystemAccount (#3828)
* Add error when using init on SystemAccount * error fix * add descriptive error message
1 parent 6f76df4 commit 3afd82e

File tree

1 file changed

+13
-0
lines changed
  • lang/syn/src/parser/accounts

1 file changed

+13
-0
lines changed

lang/syn/src/parser/accounts/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ fn constraints_cross_checks(fields: &[AccountField]) -> ParseResult<()> {
9393
})
9494
.collect();
9595

96+
for field in &init_fields {
97+
if matches!(field.ty, Ty::SystemAccount) {
98+
return Err(ParseError::new(
99+
field.ident.span(),
100+
"Cannot use `init` on a `SystemAccount`. \
101+
The `SystemAccount` type represents an already-existing account \
102+
owned by the system program and cannot be initialized. \
103+
If you need to create a new account, use a more specific account type \
104+
or `UncheckedAccount` and perform manual initialization instead.",
105+
));
106+
}
107+
}
108+
96109
if !init_fields.is_empty() {
97110
// init needs system program.
98111

0 commit comments

Comments
 (0)