Skip to content

fix(rust_spec): Add doc strings to generated error enum and variants - #1689

Open
willemneal wants to merge 1 commit into
stellar:mainfrom
theahaco:fix/comments_on_errors
Open

fix(rust_spec): Add doc strings to generated error enum and variants#1689
willemneal wants to merge 1 commit into
stellar:mainfrom
theahaco:fix/comments_on_errors

Conversation

@willemneal

Copy link
Copy Markdown
Contributor

What

Insert in doc strings into generated error types and each of their variants

Why

This way IDEs and generated rust code in generally will add the provided documentation to make it easier for devs to understand what they mean.

Known limitations

N/A

Given that the comments exist in the spec it is useful for DevX to see these comments when working with generated contracts and understanding their errors.
Copilot AI review requested due to automatic review settings January 20, 2026 21:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds documentation strings to generated error enums and their variants in the Soroban Rust SDK's spec code generation.

Changes:

  • Modified generate_error_enum function to include doc attributes for error enums and their variants
  • Added test coverage for the new documentation generation functionality

@leighmcculloch leighmcculloch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See:

// IMPORTANT: The "docs" fields of spec entries are not output in Rust token
// streams as rustdocs, because rustdocs can contain Rust code, and that code
// will be executed. Generated code may be generated from untrusted Wasm
// containing untrusted spec docs.

Making it as safe as possible to contractimport! an untrusted contract is the tradeoff. It's a tradeoff with a cost for sure, but I think the tradeoff is more valuable.

@willemneal

Copy link
Copy Markdown
Contributor Author

Do you mean as doc tests? Could we not ban code blocks?

@willemneal willemneal closed this Jan 21, 2026
@willemneal willemneal reopened this Jan 21, 2026
@leighmcculloch

Copy link
Copy Markdown
Member

Do you mean as doc tests? Could we not ban code blocks?

I don't think there's a way to ban code blocks within rust tests. The code generator would have to sanitize them away, or mark code blocks as non-executable, and guard against injection attacks.

@willemneal

Copy link
Copy Markdown
Contributor Author

Do you mean as doc tests? Could we not ban code blocks?

I don't think there's a way to ban code blocks within rust tests. The code generator would have to sanitize them away, or mark code blocks as non-executable, and guard against injection attacks.

I meant that we just don't even generate the doc string if there is a code block. Since they aren't necessary for errors anyway.

@leighmcculloch

Copy link
Copy Markdown
Member

we just don't even generate the doc string if there is a code block

That's still doing sanitizing with the same challenges and risks, just moving it to another spot.

And that'd put the protection on the generation side, when the protection needs to be on the importer side. Otherwise anyone could circumvent the protection by simply crafting their own docs that contained a doctest.

they aren't necessary for errors anyway

This issue applies to doc strings across all entries in the spec, not just errors.

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.

3 participants