Skip to content

fix(error-handling): use correct SDK API classes (gl.vm.UserError, gl.advanced.user_error_immediate)#363

Open
acastellana wants to merge 1 commit intogenlayerlabs:mainfrom
acastellana:fix/error-handling-api-classes
Open

fix(error-handling): use correct SDK API classes (gl.vm.UserError, gl.advanced.user_error_immediate)#363
acastellana wants to merge 1 commit intogenlayerlabs:mainfrom
acastellana:fix/error-handling-api-classes

Conversation

@acastellana
Copy link
Contributor

@acastellana acastellana commented Mar 12, 2026

Problem

The error-handling docs use gl.UserError and gl.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.UserErrordoes not exist
  • genlayer.gl.user_error_immediatedoes not exist

The correct classes are:

  • genlayer.gl.vm.UserError → ✅ exists, documented
  • genlayer.gl.advanced.user_error_immediate → ✅ exists, documented

Also confirmed against production intelligent contracts (multiple deployed contracts on GenLayer testnet) — all use gl.vm.UserError and work correctly.

Changes

  • gl.UserErrorgl.vm.UserError (4 occurrences)
  • gl.user_error_immediategl.advanced.user_error_immediate (1 occurrence)

Summary by CodeRabbit

  • Documentation
    • Updated error-handling documentation with revised API paths. Code examples now reflect the reorganized structure for error classes and utility functions in intelligent contracts.

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.
@vercel
Copy link
Contributor

vercel bot commented Mar 12, 2026

Someone is attempting to deploy a commit to the YeagerAI Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link

netlify bot commented Mar 12, 2026

Deploy Preview for genlayer-docs ready!

Name Link
🔨 Latest commit 22cb42c
🔍 Latest deploy log https://app.netlify.com/projects/genlayer-docs/deploys/69b25f5652248a000877cf7e
😎 Deploy Preview https://deploy-preview-363--genlayer-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Documentation updated to reflect API namespace reorganization, with UserError class moved from gl.UserError to gl.vm.UserError and user_error_immediate helper moved from gl.user_error_immediate to gl.advanced.user_error_immediate. Exception handling examples also updated accordingly.

Changes

Cohort / File(s) Summary
Error Handling Documentation
pages/developers/intelligent-contracts/features/error-handling.mdx
Updated API references in code examples: gl.UserErrorgl.vm.UserError, gl.user_error_immediategl.advanced.user_error_immediate, and corresponding exception catch clauses.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 The namespaces hop and rearrange,
From shallow gl to vm's range,
Advanced paths now hold the key,
Our docs dance with clarity!
✨🔧

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: correcting the SDK API classes used in error-handling documentation.
Description check ✅ Passed The description provides a detailed problem statement, verification against the SDK API reference, and clear documentation of all changes made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7155a37 and 22cb42c.

📒 Files selected for processing (1)
  • pages/developers/intelligent-contracts/features/error-handling.mdx

Comment on lines +63 to +68
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:
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 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:


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.

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.

1 participant