π Debugging β
When your iApp doesn't work as expected, debugging in the TEE environment requires specific techniques. This guide helps you identify issues and optimize your iApp's performance.
Task Execution Lifecycle β
Understanding how your task progresses through the iExec network:
Key Stages β
- Deal Creation - Orders matched, funds locked
- Task Initialization - Workers selected for execution
- iApp Execution - Your code runs inside TEE
- Result Processing - Results encrypted and uploaded
- Task Completion - Results available for download
Most failures happen during stages 2-4
Monitoring your Tasks β
iExec Explorer β
Track your tasks at explorer.iex.ec:
- Search by
taskId
or deal ID - Check status:
PENDING
βACTIVE
βCOMPLETED/FAILED
- View error messages if execution fails
Status in Code β
ts
const response = await dataProtectorCore.processProtectedData({
protectedData: '0x123abc...',
app: '0x456def...',
onStatusUpdate: ({ title, isDone }) => {
console.log(`Status: ${title} - Done: ${isDone}`);
},
});
Debug Commands β
Local Testing β
bash
# Test your iApp locally
iapp test --args "model=bert threshold=0.8"
iapp test --secrets "key1=value1,key2=value2"
# Mock protected data for testing
iapp mock protectedData
iapp test --protectedData "mock_name"
Remote Debugging β
bash
# Deploy and run
iapp deploy
iapp run <iapp-address>
# Debug failed executions
iapp debug <taskId>
Task Information β
bash
# View task details
iexec task show <taskId>
# Download results (if completed)
iexec task show <taskId> --download
Common Issues β
β±οΈ Task Timeout β
- Cause: Code takes too long to execute
- Solution: Optimize algorithms, reduce input sizes, use appropriate task category
πΎ Memory Issues β
- Cause: Loading large files, memory leaks, TEE constraints
- Solution: Process data in chunks, use streaming, optimize memory usage
π Input/Output Problems β
- Cause: Wrong file paths, missing
computed.json
- Solution: Always create
computed.json
, verify environment variables
python
# Always create computed.json
import json, os
computed = {"deterministic-output-path": f"{os.environ['IEXEC_OUT']}/result.json"}
with open(f"{os.environ['IEXEC_OUT']}/computed.json", 'w') as f:
json.dump(computed, f)
β οΈ Dataset Type Unmatching β
- Cause: The dataset type specified in the frontend (protectData) does not match with the dataset type specified in the iApp
- Solution: Check both dataset types
Best Practices β
π Input Validation β
python
import os, sys
# Check required environment variables
if not os.environ.get('IEXEC_IN') or not os.environ.get('IEXEC_OUT'):
print("ERROR: Missing IEXEC_IN or IEXEC_OUT")
sys.exit(1)
# Validate arguments
if len(sys.argv) < 2:
print("ERROR: Missing required arguments")
sys.exit(1)
π Clear Error Messages β
python
try:
# Your processing logic
result = process_data(data)
except Exception as e:
print(f"ERROR: Processing failed: {str(e)}")
sys.exit(1)
π Safe File Operations β
python
import os, json
# Always ensure output directory exists
iexec_out = os.environ['IEXEC_OUT']
os.makedirs(iexec_out, exist_ok=True)
# Write results safely
try:
with open(f"{iexec_out}/result.json", 'w') as f:
json.dump(result_data, f)
except Exception as e:
print(f"ERROR: Failed to write results: {e}")
sys.exit(1)
What's Next? β
Continue improving your iApps:
- Inputs and Outputs - Handle data in TEE
- How to Get and Decrypt Results - Retrieve results