Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ User-generated errors with UTF-8 encoded messages:

```python
# Can be caught in current sub-vm
raise gl.UserError("Invalid input")
raise gl.vm.UserError("Invalid input")

# Immediate user error, more efficient but can't be caught
gl.user_error_immediate("Insufficient funds")
gl.advanced.user_error_immediate("Insufficient funds")
```

## VMError
Expand All @@ -45,11 +45,11 @@ Handle user errors from sub-VMs:

```python
def risky_operation():
raise gl.UserError("Operation failed")
raise gl.vm.UserError("Operation failed")

try:
result = gl.eq_principle.strict_eq(risky_operation)
except gl.UserError as e:
except gl.vm.UserError as e:
print(f"Caught user error: {e.message}")
```

Expand All @@ -60,12 +60,12 @@ Errors flow from non-deterministic to deterministic code:
```python
def nondet_block():
if some_condition:
raise gl.UserError("INVALID_STATE")
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:
Comment on lines +63 to +68
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.

if e.message == "INVALID_STATE":
# Handle specific error condition
pass
Expand Down
Loading