Return errors instead of panicking in soroban-spec-rust#1810
Open
leighmcculloch wants to merge 7 commits intomainfrom
Open
Return errors instead of panicking in soroban-spec-rust#1810leighmcculloch wants to merge 7 commits intomainfrom
leighmcculloch wants to merge 7 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
GenerateErrorand convert spec-to-Rust generation functions (generate_*and*_with_options) to returnResult<_, GenerateError>instead of panicking. - Add
syn_ext::str_to_identto validate/parse identifiers and map invalid UTF-8 / invalid idents intoGenerateError. - Propagate generation failures up through
generate_from_wasm_with_optionsvia a newGenerateFromFileError::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. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_optionsvariants) from infallible to fallible, returningGenerateError. PropagateGenerateErrorup throughgenerate_from_wasm_with_optionsand 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