Skip to content

Return errors instead of panicking in soroban-spec-rust#1810

Open
leighmcculloch wants to merge 7 commits intomainfrom
str-to-ident-into-ident
Open

Return errors instead of panicking in soroban-spec-rust#1810
leighmcculloch wants to merge 7 commits intomainfrom
str-to-ident-into-ident

Conversation

@leighmcculloch
Copy link
Copy Markdown
Member

@leighmcculloch leighmcculloch commented Apr 1, 2026

What

Convert all code-generation functions in soroban-spec-rust (generate_struct, generate_union, generate_enum, generate_error_enum, generate_event, generate_function, and their _with_options variants) from infallible to fallible, returning GenerateError. Propagate GenerateError up through generate_from_wasm_with_options and other fns.

Why

The generator panicked on Wasm contracts with invalid UTF-8 bytes or non-identifier strings in spec entry names. Existing TODOs in the source acknowledged this.

Close #1765

Targeting

v26

@leighmcculloch leighmcculloch requested a review from mootz12 April 1, 2026 07:20
@leighmcculloch leighmcculloch marked this pull request as ready for review April 1, 2026 13:14
Copilot AI review requested due to automatic review settings April 1, 2026 13:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the soroban-spec-rust code generator to stop panicking on malformed contract specs (e.g., invalid UTF-8 or invalid Rust identifiers) by making the generation APIs fallible and returning a new GenerateError, propagating failures up through the public entrypoints.

Changes:

  • Introduce GenerateError and convert spec-to-Rust generation functions (generate_* and *_with_options) to return Result<_, GenerateError> instead of panicking.
  • Add syn_ext::str_to_ident to validate/parse identifiers and map invalid UTF-8 / invalid idents into GenerateError.
  • Propagate generation failures up through generate_from_wasm_with_options via a new GenerateFromFileError::Generate(...) variant and add tests for invalid UTF-8/ident cases.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
soroban-spec-rust/src/types.rs Introduces GenerateError, converts type/event generators to Result, and adds tests for invalid UTF-8/ident inputs.
soroban-spec-rust/src/trait.rs Converts trait/function generation to Result and uses str_to_ident + fallible type generation.
soroban-spec-rust/src/syn_ext.rs New helper module to safely convert spec strings/symbols into proc_macro2::Ident.
soroban-spec-rust/src/lib.rs Makes top-level generation APIs fallible and maps generation errors into GenerateFromFileError.

leighmcculloch and others added 2 commits April 3, 2026 00:39
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

soroban-spec-rust panics on invalid UTF-8 or invalid identifiers in spec entries

2 participants