Skip to content

sdk: Stable numeric error codes for i18n support#716

Merged
cdecker merged 2 commits into
mainfrom
2026w20-num-errors
May 20, 2026
Merged

sdk: Stable numeric error codes for i18n support#716
cdecker merged 2 commits into
mainfrom
2026w20-num-errors

Conversation

@cdecker
Copy link
Copy Markdown
Collaborator

@cdecker cdecker commented May 13, 2026

Summary

  • Replace gl-sdk tuple-style error variants with named-field variants carrying code: i32, message: String, and values: HashMap<String, String>
  • Each error has a stable numeric code (1000-1099 node identity, 1100-1199 credentials, 2000-2099 RPC, 3000-3099 validation, 9000-9099 generic) enabling host-language i18n lookup
  • The values map provides structured interpolation keys so callers can fill translated templates (e.g., "Node {node_id} already exists")
  • Constructor functions (Error::rpc(), Error::other(), etc.) keep call sites clean
  • Regenerated Python, Kotlin, Swift, and Ruby bindings — all expose .code, .message, .values on error subclasses

Test plan

  • cargo build -p gl-sdk compiles cleanly
  • Verified generated Python bindings have code, message, values attributes on all Error subclasses
  • Verified generated Kotlin bindings have val code: Int, val message: String, val values: Map<String, String>
  • Verified generated Swift bindings have code: Int32, message: String, values: [String: String]
  • Integration test with host-language error catching and i18n template interpolation

🤖 Generated with Claude Code

@michaelbship
Copy link
Copy Markdown
Collaborator

@cdecker we will follow this up with a doc fix as well

@cdecker cdecker mentioned this pull request May 20, 2026
@cdecker cdecker force-pushed the 2026w20-num-errors branch from cfce6c1 to f031292 Compare May 20, 2026 15:49
@cdecker
Copy link
Copy Markdown
Collaborator Author

cdecker commented May 20, 2026

Rebased on top of main. Changes during rebase:

  • Fixed all callers added on main since the original PR (credentials.rs, input.rs, lib.rs, logging.rs, node.rs) — they used old tuple-style Error::Other(...) / Error::Rpc(...) etc. and now use the new constructor methods (Error::other(), Error::rpc(), Error::duplicate_node(), etc.)
  • Removed the stray bindings/glsdk.py — Python bindings belong in glsdk/, other languages in bindings/
  • Moved all derived files (glsdk.py + Kotlin/Swift/Ruby) into the second commit, keeping commit 1 purely Rust source changes
  • Regenerated glsdk.py from the updated Rust definitions

Replace tuple-style error variants with named-field variants carrying
code (i32), message (String), and values (HashMap<String, String>).
This allows host-language callers to look up translated error strings
by numeric code and interpolate structured values, rather than parsing
English messages.

Error code ranges: 1000-1099 node identity, 1100-1199 credentials,
2000-2099 RPC, 3000-3099 input validation, 9000-9099 generic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cdecker cdecker force-pushed the 2026w20-num-errors branch from f031292 to 17a926e Compare May 20, 2026 16:41
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cdecker cdecker force-pushed the 2026w20-num-errors branch from 17a926e to 9aa24a1 Compare May 20, 2026 17:34
@cdecker cdecker merged commit d48c3e9 into main May 20, 2026
16 checks passed
@cdecker cdecker deleted the 2026w20-num-errors branch May 20, 2026 18:59
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.

2 participants