fix(error-handling): use correct SDK API classes (gl.vm.UserError, gl.advanced.user_error_immediate)#363
Conversation
gl.UserError and gl.user_error_immediate do not exist in the SDK. The correct classes per genlayer.gl module source are: - gl.vm.UserError (genlayer.gl.vm.UserError) - gl.advanced.user_error_immediate (genlayer.gl.advanced.user_error_immediate) Verified against SDK API reference at sdk.genlayer.com/main/api/genlayer.html and production intelligent contracts using these APIs successfully.
|
Someone is attempting to deploy a commit to the YeagerAI Team on Vercel. A member of the Team first needs to authorize it. |
✅ Deploy Preview for genlayer-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughDocumentation updated to reflect API namespace reorganization, with UserError class moved from Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pages/developers/intelligent-contracts/features/error-handling.mdx`:
- Around line 63-68: The code uses gl.vm.UserError when raising and catching the
user error; update both the raise statement and the except clause to use the
SDK-recommended gl.UserError instead (i.e., replace gl.vm.UserError with
gl.UserError in the raise and in the except that wraps
gl.eq_principle.strict_eq(nondet_block)) so the example matches official SDK
usage.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dad63af7-fc1d-41e7-bec9-532fc68a8630
📒 Files selected for processing (1)
pages/developers/intelligent-contracts/features/error-handling.mdx
| raise gl.vm.UserError("INVALID_STATE") | ||
| return "success" | ||
|
|
||
| try: | ||
| gl.eq_principle.strict_eq(nondet_block) | ||
| except gl.UserError as e: | ||
| except gl.vm.UserError as e: |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Official GenLayer SDK API reference: for user-error propagation examples, is gl.vm.UserError the correct class to both raise and catch?
💡 Result:
Yes—gl.vm.UserError is the underlying exception type in the official SDK API reference (genlayer.gl.vm.UserError). (sdk.genlayer.com)
However, the official error-handling examples use gl.UserError for raising and catching (i.e., via import genlayer.gl as gl). So for “user-error propagation” examples, you should follow the docs and raise/catch gl.UserError, while recognizing it corresponds to the VM’s UserError type documented under gl.vm. (docs.genlayer.com)
Citations:
- 1: https://sdk.genlayer.com/main/api/genlayer.html
- 2: https://docs.genlayer.com/developers/intelligent-contracts/features/error-handling
Fix namespace to match official SDK examples: use gl.UserError instead of gl.vm.UserError.
The example at lines 63-68 uses gl.vm.UserError, but the official SDK documentation uses gl.UserError for raising and catching user errors. While gl.vm.UserError is the underlying implementation type, the official examples and best practices recommend using gl.UserError for consistency and clarity. Update both the raise statement and the except clause to use gl.UserError.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pages/developers/intelligent-contracts/features/error-handling.mdx` around
lines 63 - 68, The code uses gl.vm.UserError when raising and catching the user
error; update both the raise statement and the except clause to use the
SDK-recommended gl.UserError instead (i.e., replace gl.vm.UserError with
gl.UserError in the raise and in the except that wraps
gl.eq_principle.strict_eq(nondet_block)) so the example matches official SDK
usage.
Problem
The error-handling docs use
gl.UserErrorandgl.user_error_immediate, but neither of these exists in the SDK.Verification
Checked against the SDK API reference at https://sdk.genlayer.com/main/api/genlayer.html:
genlayer.gl.UserError→ does not existgenlayer.gl.user_error_immediate→ does not existThe correct classes are:
genlayer.gl.vm.UserError→ ✅ exists, documentedgenlayer.gl.advanced.user_error_immediate→ ✅ exists, documentedAlso confirmed against production intelligent contracts (multiple deployed contracts on GenLayer testnet) — all use
gl.vm.UserErrorand work correctly.Changes
gl.UserError→gl.vm.UserError(4 occurrences)gl.user_error_immediate→gl.advanced.user_error_immediate(1 occurrence)Summary by CodeRabbit