File tree Expand file tree Collapse file tree 4 files changed +19
-8
lines changed
Expand file tree Collapse file tree 4 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ pub fn gen_idl_print_fn_error(error: &Error) -> TokenStream {
1212 "__anchor_private_print_idl_error_{}" ,
1313 error. ident. to_string( ) . to_snake_case( )
1414 ) ;
15+ let offset = match & error. args {
16+ Some ( args) => {
17+ let offset = & args. offset ;
18+ quote ! { #offset }
19+ }
20+ None => quote ! { :: anchor_lang:: error:: ERROR_CODE_OFFSET } ,
21+ } ;
1522
1623 let error_codes = error
1724 . codes
@@ -26,7 +33,7 @@ pub fn gen_idl_print_fn_error(error: &Error) -> TokenStream {
2633
2734 quote ! {
2835 #idl:: IdlErrorCode {
29- code: anchor_lang :: error :: ERROR_CODE_OFFSET + #id,
36+ code: #offset + #id,
3037 name: #name. into( ) ,
3138 msg: #msg,
3239 }
Original file line number Diff line number Diff line change @@ -680,9 +680,8 @@ impl Parse for ErrorArgs {
680680 return Err ( ParseError :: new ( offset_span, "expected keyword offset" ) ) ;
681681 }
682682 stream. parse :: < Token ! [ =] > ( ) ?;
683- Ok ( ErrorArgs {
684- offset : stream. parse ( ) ?,
685- } )
683+ let offset: LitInt = stream. parse ( ) ?;
684+ Ok ( ErrorArgs { offset } )
686685 }
687686}
688687
Original file line number Diff line number Diff line change 413413 ],
414414 "errors" : [
415415 {
416- "code" : 6000 ,
416+ "code" : 500000 ,
417417 "name" : " SomeError" ,
418418 "msg" : " Example error."
419419 },
420420 {
421- "code" : 6001 ,
421+ "code" : 500001 ,
422422 "name" : " OtherError" ,
423423 "msg" : " Another error."
424424 },
425425 {
426- "code" : 6002 ,
426+ "code" : 500002 ,
427427 "name" : " ErrorWithoutMsg"
428+ },
429+ {
430+ "code" : 500500 ,
431+ "name" : " WithDiscrim"
428432 }
429433 ],
430434 "types" : [
Original file line number Diff line number Diff line change @@ -300,13 +300,14 @@ pub struct Initialize2<'info> {
300300#[ derive( Accounts ) ]
301301pub struct CauseError { }
302302
303- #[ error_code]
303+ #[ error_code( offset = 500_000 ) ]
304304pub enum ErrorCode {
305305 #[ msg( "Example error." ) ]
306306 SomeError ,
307307 #[ msg( "Another error." ) ]
308308 OtherError ,
309309 ErrorWithoutMsg ,
310+ WithDiscrim = 500 ,
310311}
311312
312313mod some_other_module {
You can’t perform that action at this time.
0 commit comments