Skip to content

feat: replacing panic, unwrap & unimplemented error outs with syn::Error#4291

Open
Manudasari265 wants to merge 6 commits intosolana-foundation:masterfrom
Manudasari265:feat/syn-err-macros
Open

feat: replacing panic, unwrap & unimplemented error outs with syn::Error#4291
Manudasari265 wants to merge 6 commits intosolana-foundation:masterfrom
Manudasari265:feat/syn-err-macros

Conversation

@Manudasari265
Copy link

@Manudasari265 Manudasari265 commented Mar 6, 2026

Summary of Changes

Audited all relevant proc-macro crates and replaced reachable panic paths with syn::Error diagnostics that point at the offending token in the user's source. Intentionally kept safe internal invariants are marked with // safe-unwrap: comments. Added CI lint script that fails the build on any unguarded panic path in proc-macro crates

Audit Fixes

anchor-derive-space (lang/derive/space)

  • Replace unimplemented!() with syn::Error when #[derive(InitSpace)] is applied to a union type
  • Replace panic!("Type {ty:?} is not supported") with syn::Error::new_spanned for unsupported field types (e.g. &str, *const T, dyn Trait)

anchor-derive-accounts (lang/derive/accounts)

  • No reachable panic paths found - delegates entirely to anchor-syn

anchor-derive-serde (lang/derive/serde)

  • Replace .expect() on proc_macro_crate::crate_name("anchor-lang") with syn::Error for missing dependency

anchor-attribute-account (lang/attribute/account)

  • Replace panic! with syn::Error when #[derive(ZeroCopyAccessor)] is applied to a non-named-fields struct
  • Replace panic!/.expect() with syn::Error for invalid #[accessor] attribute syntax (missing args, empty parens, wrong token)
  • Replace panic! with syn::Error for invalid #[zero_copy(...)] arguments (also resolves existing TODO comment)

anchor-attribute-access-control (lang/attribute/access-control)

  • Replace .unwrap() with syn::Error when #[access_control(...)] arguments fail to tokenize

anchor-attribute-program (lang/attribute/program)

  • Replace unimplemented! in convert_idl_type_to_str for unhandled IdlType variants in declare_program! (also resolves existing TODO comment)
  • Replace unimplemented! for unsupported IDL serialization types
  • Replace unimplemented! for unsupported IDL repr types

CI Lint

  • Added scripts/check-proc-macro-panics.sh - fails if any unguarded panic!/unwrap()/unimplemented!/expect() appears in proc-macro crates; intentionally kept safe invariants are
    exempted via // safe-unwrap: inline comments
  • Added proc-macro-panic-lint job to .github/workflows/global-lint.yaml

fixes #4280

Signed-off-by: Manoj Dasari <dasarimanoj265@gmail.com>
@vercel
Copy link

vercel bot commented Mar 6, 2026

@Manudasari265 is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@Manudasari265 Manudasari265 changed the title WIP: identifying panic, unwrap & unimplemented error outs feat: identifying panic, unwrap & unimplemented error outs Mar 7, 2026
@Manudasari265 Manudasari265 changed the title feat: identifying panic, unwrap & unimplemented error outs feat: replacing panic, unwrap & unimplemented error outs with syn::Error Mar 7, 2026
@Manudasari265 Manudasari265 marked this pull request as ready for review March 8, 2026 18:18
@Manudasari265
Copy link
Author

hi @nutafrost PR is ready for review, audited and addressed all the proc-macro crates. kindly let me know if I have missed any or to address any

- uses: actions/checkout@v4
- name: Check for panic paths in proc-macro crates
# Manually run locally via: bash scripts/check-proc-macro-panics.sh
run: bash scripts/check-proc-macro-panics.sh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods instead of grepping? This will help catch things locally (at least when people run Clippy)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate panic paths in all proc-macro crates

2 participants