|
1 | 1 | --- |
2 | 2 | title: Debugging Your iApp |
3 | | -description: Debugging Your iApp |
| 3 | +description: |
| 4 | + Troubleshoot and optimize your iApp execution in the TEE environment |
4 | 5 | --- |
5 | 6 |
|
6 | | -# Debugging Your iApp |
| 7 | +# 🐛 Debugging Your iApp |
7 | 8 |
|
8 | | -This page is under development. |
| 9 | +**When your iApp doesn't work as expected, debugging in the TEE environment |
| 10 | +requires specific techniques.** This guide helps you identify issues and |
| 11 | +optimize your iApp's performance. |
9 | 12 |
|
10 | | -<!-- TODO: Add the debugging guide --> |
| 13 | +## Task Execution Lifecycle |
| 14 | + |
| 15 | +Understanding how your task progresses through the iExec network: |
| 16 | + |
| 17 | +### Key Stages |
| 18 | + |
| 19 | +1. **Deal Creation** - Orders matched, funds locked |
| 20 | +2. **Task Initialization** - Workers selected for execution |
| 21 | +3. **iApp Execution** - Your code runs inside TEE |
| 22 | +4. **Result Processing** - Results encrypted and uploaded |
| 23 | +5. **Task Completion** - Results available for download |
| 24 | + |
| 25 | +**Most failures happen during stages 2-4** |
| 26 | + |
| 27 | +## Monitoring Your Tasks |
| 28 | + |
| 29 | +### iExec Explorer |
| 30 | + |
| 31 | +Track your tasks at [explorer.iex.ec](https://explorer.iex.ec): |
| 32 | + |
| 33 | +- Search by `taskId` or deal ID |
| 34 | +- Check status: `PENDING` → `ACTIVE` → `COMPLETED/FAILED` |
| 35 | +- View error messages if execution fails |
| 36 | + |
| 37 | +### Status in Code |
| 38 | + |
| 39 | +```ts twoslash |
| 40 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 41 | + |
| 42 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 43 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 44 | +// ---cut--- |
| 45 | +const response = await dataProtectorCore.processProtectedData({ |
| 46 | + protectedData: '0x123abc...', |
| 47 | + app: '0x456def...', |
| 48 | + onStatusUpdate: ({ title, isDone }) => { |
| 49 | + console.log(`Status: ${title} - Done: ${isDone}`); |
| 50 | + }, |
| 51 | +}); |
| 52 | +``` |
| 53 | + |
| 54 | +## Debug Commands |
| 55 | + |
| 56 | +### Local Testing |
| 57 | + |
| 58 | +```bash |
| 59 | +# Test your iApp locally |
| 60 | +iapp test --args "model=bert threshold=0.8" |
| 61 | +iapp test --secrets "key1=value1,key2=value2" |
| 62 | + |
| 63 | +# Mock protected data for testing |
| 64 | +iapp mock protectedData |
| 65 | +iapp test --protectedData "mock_name" |
| 66 | +``` |
| 67 | + |
| 68 | +### Remote Debugging |
| 69 | + |
| 70 | +```bash |
| 71 | +# Deploy and run |
| 72 | +iapp deploy |
| 73 | +iapp run <iapp-address> |
| 74 | + |
| 75 | +# Debug failed executions |
| 76 | +iapp debug <taskId> |
| 77 | +``` |
| 78 | + |
| 79 | +### Task Information |
| 80 | + |
| 81 | +```bash |
| 82 | +# View task details |
| 83 | +iexec task show <taskId> |
| 84 | + |
| 85 | +# Download results (if completed) |
| 86 | +iexec task show <taskId> --download |
| 87 | +``` |
| 88 | + |
| 89 | +## Common Issues |
| 90 | + |
| 91 | +### ⏱️ **Task Timeout** |
| 92 | + |
| 93 | +- **Cause**: Code takes too long to execute |
| 94 | +- **Solution**: Optimize algorithms, reduce input sizes, use appropriate task |
| 95 | + category |
| 96 | + |
| 97 | +### 💾 **Memory Issues** |
| 98 | + |
| 99 | +- **Cause**: Loading large files, memory leaks, TEE constraints |
| 100 | +- **Solution**: Process data in chunks, use streaming, optimize memory usage |
| 101 | + |
| 102 | +### 📁 **Input/Output Problems** |
| 103 | + |
| 104 | +- **Cause**: Wrong file paths, missing `computed.json` |
| 105 | +- **Solution**: Always create `computed.json`, verify environment variables |
| 106 | + |
| 107 | +```python |
| 108 | +# Always create computed.json |
| 109 | +import json, os |
| 110 | +computed = {"deterministic-output-path": f"{os.environ['IEXEC_OUT']}/result.json"} |
| 111 | +with open(f"{os.environ['IEXEC_OUT']}/computed.json", 'w') as f: |
| 112 | + json.dump(computed, f) |
| 113 | +``` |
| 114 | + |
| 115 | +### ⚠️ **Dataset type unmatching** |
| 116 | + |
| 117 | +- **Cause**: The dataset type specified in the frontend (protectData) does not |
| 118 | + match with the dataset type specified in the iApp |
| 119 | +- **Solution**: Check both dataset types |
| 120 | + |
| 121 | +## Best Practices |
| 122 | + |
| 123 | +### 🔍 **Input Validation** |
| 124 | + |
| 125 | +```python |
| 126 | +import os, sys |
| 127 | + |
| 128 | +# Check required environment variables |
| 129 | +if not os.environ.get('IEXEC_IN') or not os.environ.get('IEXEC_OUT'): |
| 130 | + print("ERROR: Missing IEXEC_IN or IEXEC_OUT") |
| 131 | + sys.exit(1) |
| 132 | + |
| 133 | +# Validate arguments |
| 134 | +if len(sys.argv) < 2: |
| 135 | + print("ERROR: Missing required arguments") |
| 136 | + sys.exit(1) |
| 137 | +``` |
| 138 | + |
| 139 | +### 📝 **Clear Error Messages** |
| 140 | + |
| 141 | +```python |
| 142 | +try: |
| 143 | + # Your processing logic |
| 144 | + result = process_data(data) |
| 145 | +except Exception as e: |
| 146 | + print(f"ERROR: Processing failed: {str(e)}") |
| 147 | + sys.exit(1) |
| 148 | +``` |
| 149 | + |
| 150 | +### 🔒 **Safe File Operations** |
| 151 | + |
| 152 | +```python |
| 153 | +import os, json |
| 154 | + |
| 155 | +# Always ensure output directory exists |
| 156 | +iexec_out = os.environ['IEXEC_OUT'] |
| 157 | +os.makedirs(iexec_out, exist_ok=True) |
| 158 | + |
| 159 | +# Write results safely |
| 160 | +try: |
| 161 | + with open(f"{iexec_out}/result.json", 'w') as f: |
| 162 | + json.dump(result_data, f) |
| 163 | +except Exception as e: |
| 164 | + print(f"ERROR: Failed to write results: {e}") |
| 165 | + sys.exit(1) |
| 166 | +``` |
| 167 | + |
| 168 | +## What's Next? |
| 169 | + |
| 170 | +Continue improving your iApps: |
| 171 | + |
| 172 | +- **[Inputs and Outputs](/build_iapp/guides/inputs-and-outputs)** - Handle data |
| 173 | + in TEE |
| 174 | +- **[How to Get and Decrypt Results](/build_iapp/guides/how-to-get-and-decrypt-results)** - |
| 175 | + Retrieve results |
0 commit comments