@xano/developer-mcp 1.0.74 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -37
- package/dist/cli_docs/index.d.ts +13 -37
- package/dist/cli_docs/index.js +28 -39
- package/dist/cli_docs/topics/integration.js +1 -1
- package/dist/cli_docs/topics/workspace.js +1 -1
- package/dist/index.js +58 -55
- package/dist/lib.d.ts +3 -1
- package/dist/lib.js +1 -1
- package/dist/meta_api_docs/format.js +1 -1
- package/dist/meta_api_docs/index.d.ts +14 -42
- package/dist/meta_api_docs/index.js +34 -46
- package/dist/tools/cli_docs.d.ts +2 -3
- package/dist/tools/cli_docs.js +3 -5
- package/dist/tools/define_tool.d.ts +47 -0
- package/dist/tools/define_tool.js +36 -0
- package/dist/tools/index.d.ts +88 -221
- package/dist/tools/index.js +80 -109
- package/dist/tools/mcp_version.d.ts +4 -25
- package/dist/tools/mcp_version.js +12 -19
- package/dist/tools/meta_api_docs.d.ts +2 -3
- package/dist/tools/meta_api_docs.js +3 -5
- package/dist/tools/validate_xanoscript.d.ts +18 -65
- package/dist/tools/validate_xanoscript.js +56 -54
- package/dist/tools/xanoscript_docs.d.ts +25 -74
- package/dist/tools/xanoscript_docs.js +86 -83
- package/dist/xanoscript_docs/README.md +5 -5
- package/dist/xanoscript_docs/addons.md +1 -3
- package/dist/xanoscript_docs/apis.md +2 -2
- package/dist/xanoscript_docs/database.md +1 -1
- package/dist/xanoscript_docs/essentials.md +6 -6
- package/dist/xanoscript_docs/functions.md +3 -3
- package/dist/xanoscript_docs/integrations.md +5 -5
- package/dist/xanoscript_docs/middleware.md +1 -1
- package/dist/xanoscript_docs/performance.md +4 -4
- package/dist/xanoscript_docs/realtime.md +2 -2
- package/dist/xanoscript_docs/security.md +3 -6
- package/dist/xanoscript_docs/survival.md +1 -1
- package/dist/xanoscript_docs/syntax/string-filters.md +1 -1
- package/dist/xanoscript_docs/syntax.md +10 -12
- package/dist/xanoscript_docs/tasks.md +1 -2
- package/dist/xanoscript_docs/tools.md +3 -5
- package/dist/xanoscript_docs/types.md +2 -2
- package/dist/xanoscript_docs/unit-testing.md +1 -1
- package/dist/xanoscript_docs/workflow-tests.md +1 -1
- package/dist/xanoscript_docs/working.md +4 -4
- package/package.json +5 -4
- package/dist/api_docs/format.d.ts +0 -5
- package/dist/api_docs/format.js +0 -171
- package/dist/api_docs/index.d.ts +0 -52
- package/dist/api_docs/index.js +0 -111
- package/dist/api_docs/topics/agent.d.ts +0 -2
- package/dist/api_docs/topics/agent.js +0 -142
- package/dist/api_docs/topics/api.d.ts +0 -2
- package/dist/api_docs/topics/api.js +0 -176
- package/dist/api_docs/topics/apigroup.d.ts +0 -2
- package/dist/api_docs/topics/apigroup.js +0 -124
- package/dist/api_docs/topics/authentication.d.ts +0 -2
- package/dist/api_docs/topics/authentication.js +0 -61
- package/dist/api_docs/topics/branch.d.ts +0 -2
- package/dist/api_docs/topics/branch.js +0 -73
- package/dist/api_docs/topics/file.d.ts +0 -2
- package/dist/api_docs/topics/file.js +0 -70
- package/dist/api_docs/topics/function.d.ts +0 -2
- package/dist/api_docs/topics/function.js +0 -164
- package/dist/api_docs/topics/history.d.ts +0 -2
- package/dist/api_docs/topics/history.js +0 -149
- package/dist/api_docs/topics/mcp_server.d.ts +0 -2
- package/dist/api_docs/topics/mcp_server.js +0 -139
- package/dist/api_docs/topics/middleware.d.ts +0 -2
- package/dist/api_docs/topics/middleware.js +0 -156
- package/dist/api_docs/topics/realtime.d.ts +0 -2
- package/dist/api_docs/topics/realtime.js +0 -112
- package/dist/api_docs/topics/start.d.ts +0 -2
- package/dist/api_docs/topics/start.js +0 -107
- package/dist/api_docs/topics/table.d.ts +0 -2
- package/dist/api_docs/topics/table.js +0 -195
- package/dist/api_docs/topics/task.d.ts +0 -2
- package/dist/api_docs/topics/task.js +0 -165
- package/dist/api_docs/topics/tool.d.ts +0 -2
- package/dist/api_docs/topics/tool.js +0 -150
- package/dist/api_docs/topics/workflows.d.ts +0 -2
- package/dist/api_docs/topics/workflows.js +0 -131
- package/dist/api_docs/topics/workspace.d.ts +0 -2
- package/dist/api_docs/topics/workspace.js +0 -153
- package/dist/api_docs/types.d.ts +0 -79
- package/dist/api_docs/types.js +0 -4
- package/dist/cli_docs/topics/run.d.ts +0 -2
- package/dist/cli_docs/topics/run.js +0 -248
- package/dist/meta_api_docs/format.test.d.ts +0 -1
- package/dist/meta_api_docs/format.test.js +0 -272
- package/dist/meta_api_docs/index.test.d.ts +0 -1
- package/dist/meta_api_docs/index.test.js +0 -128
- package/dist/meta_api_docs/types.test.d.ts +0 -1
- package/dist/meta_api_docs/types.test.js +0 -132
- package/dist/templates/init-workspace.d.ts +0 -10
- package/dist/templates/init-workspace.js +0 -278
- package/dist/templates/xanoscript-index.d.ts +0 -11
- package/dist/templates/xanoscript-index.js +0 -72
- package/dist/tools/index.test.d.ts +0 -1
- package/dist/tools/index.test.js +0 -179
- package/dist/tools/xanoscript_docs.test.d.ts +0 -1
- package/dist/tools/xanoscript_docs.test.js +0 -197
- package/dist/xanoscript.test.d.ts +0 -1
- package/dist/xanoscript.test.js +0 -421
- package/dist/xanoscript_docs/cheatsheet.md +0 -287
- package/dist/xanoscript_docs/ephemeral.md +0 -330
- package/dist/xanoscript_docs/quickstart.md +0 -692
- package/dist/xanoscript_docs/run.md +0 -196
- package/dist/xanoscript_docs/schema.md +0 -300
- package/dist/xanoscript_docs_auto/README.md +0 -119
- package/dist/xanoscript_docs_auto/agents.md +0 -446
- package/dist/xanoscript_docs_auto/apis.md +0 -517
- package/dist/xanoscript_docs_auto/control-flow.md +0 -543
- package/dist/xanoscript_docs_auto/database.md +0 -551
- package/dist/xanoscript_docs_auto/debugging.md +0 -527
- package/dist/xanoscript_docs_auto/filters.md +0 -464
- package/dist/xanoscript_docs_auto/functions.md +0 -431
- package/dist/xanoscript_docs_auto/integrations.md +0 -657
- package/dist/xanoscript_docs_auto/mcp-servers.md +0 -408
- package/dist/xanoscript_docs_auto/operators.md +0 -368
- package/dist/xanoscript_docs_auto/syntax.md +0 -287
- package/dist/xanoscript_docs_auto/tables.md +0 -447
- package/dist/xanoscript_docs_auto/tasks.md +0 -479
- package/dist/xanoscript_docs_auto/testing.md +0 -574
- package/dist/xanoscript_docs_auto/tools.md +0 -485
- package/dist/xanoscript_docs_auto/triggers.md +0 -595
- package/dist/xanoscript_docs_auto/types.md +0 -323
- package/dist/xanoscript_docs_auto/variables.md +0 -462
- package/dist/xanoscript_docs_auto/version.json +0 -5
|
@@ -1,527 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
applyTo: "**/*.xs"
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Debugging
|
|
6
|
-
|
|
7
|
-
Logging, inspecting, and debugging XanoScript execution.
|
|
8
|
-
|
|
9
|
-
## Quick Reference
|
|
10
|
-
|
|
11
|
-
| Function | Purpose |
|
|
12
|
-
|----------|---------|
|
|
13
|
-
| `debug.log` | Log value to debugger |
|
|
14
|
-
| `debug.stop` | Stop execution and inspect |
|
|
15
|
-
| `precondition` | Assert condition with error |
|
|
16
|
-
| `throw` | Raise custom error |
|
|
17
|
-
|
|
18
|
-
---
|
|
19
|
-
|
|
20
|
-
## debug.log
|
|
21
|
-
|
|
22
|
-
Log values during execution:
|
|
23
|
-
|
|
24
|
-
```xs
|
|
25
|
-
debug.log {
|
|
26
|
-
value = "Processing started"
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
debug.log {
|
|
30
|
-
value = $input
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
debug.log {
|
|
34
|
-
value = {
|
|
35
|
-
user_id: $user.id,
|
|
36
|
-
action: "login",
|
|
37
|
-
timestamp: now
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### Log with Labels
|
|
43
|
-
|
|
44
|
-
```xs
|
|
45
|
-
debug.log {
|
|
46
|
-
value = "User ID: " ~ $user.id
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
debug.log {
|
|
50
|
-
value = "Items: " ~ ($items|json_encode)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
debug.log {
|
|
54
|
-
value = "Count: " ~ ($results|count)
|
|
55
|
-
}
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Log Objects
|
|
59
|
-
|
|
60
|
-
```xs
|
|
61
|
-
debug.log {
|
|
62
|
-
value = {
|
|
63
|
-
step: "after_validation",
|
|
64
|
-
input: $input,
|
|
65
|
-
user: $user,
|
|
66
|
-
is_valid: $is_valid
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
---
|
|
72
|
-
|
|
73
|
-
## debug.stop
|
|
74
|
-
|
|
75
|
-
Stop execution and inspect state:
|
|
76
|
-
|
|
77
|
-
```xs
|
|
78
|
-
debug.stop {
|
|
79
|
-
value = "Inspection point"
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
debug.stop {
|
|
83
|
-
value = {
|
|
84
|
-
variables: {
|
|
85
|
-
user: $user,
|
|
86
|
-
items: $items,
|
|
87
|
-
total: $total
|
|
88
|
-
},
|
|
89
|
-
input: $input,
|
|
90
|
-
auth: $auth
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Conditional Stop
|
|
96
|
-
|
|
97
|
-
```xs
|
|
98
|
-
conditional {
|
|
99
|
-
if ($suspicious_value) {
|
|
100
|
-
debug.stop {
|
|
101
|
-
value = "Suspicious value detected"
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
---
|
|
108
|
-
|
|
109
|
-
## Preconditions
|
|
110
|
-
|
|
111
|
-
Validate conditions and throw typed errors:
|
|
112
|
-
|
|
113
|
-
```xs
|
|
114
|
-
precondition ($input.amount > 0) {
|
|
115
|
-
error_type = "inputerror"
|
|
116
|
-
error = "Amount must be positive"
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
precondition ($user != null) {
|
|
120
|
-
error_type = "notfound"
|
|
121
|
-
error = "User not found"
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
precondition ($auth.role == "admin") {
|
|
125
|
-
error_type = "accessdenied"
|
|
126
|
-
error = "Admin access required"
|
|
127
|
-
}
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
### Error Types
|
|
131
|
-
|
|
132
|
-
| Type | HTTP Status | Use Case |
|
|
133
|
-
|------|-------------|----------|
|
|
134
|
-
| `inputerror` | 400 | Invalid input |
|
|
135
|
-
| `accessdenied` | 403 | Unauthorized |
|
|
136
|
-
| `notfound` | 404 | Resource missing |
|
|
137
|
-
| `standard` | 500 | General error |
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## Throwing Errors
|
|
142
|
-
|
|
143
|
-
### Basic Throw
|
|
144
|
-
|
|
145
|
-
```xs
|
|
146
|
-
throw {
|
|
147
|
-
name = "ValidationError"
|
|
148
|
-
value = "Email format is invalid"
|
|
149
|
-
}
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
### With Error Code
|
|
153
|
-
|
|
154
|
-
```xs
|
|
155
|
-
throw {
|
|
156
|
-
name = "RateLimitError"
|
|
157
|
-
value = "Too many requests"
|
|
158
|
-
code = 429
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Conditional Throw
|
|
163
|
-
|
|
164
|
-
```xs
|
|
165
|
-
conditional {
|
|
166
|
-
if ($user == null) {
|
|
167
|
-
throw {
|
|
168
|
-
name = "UserNotFound"
|
|
169
|
-
value = "User with ID " ~ $input.user_id ~ " not found"
|
|
170
|
-
code = 404
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
## Try/Catch Debugging
|
|
179
|
-
|
|
180
|
-
### Log Errors
|
|
181
|
-
|
|
182
|
-
```xs
|
|
183
|
-
try_catch {
|
|
184
|
-
try {
|
|
185
|
-
function.run "risky_operation" {
|
|
186
|
-
input = $data
|
|
187
|
-
} as $result
|
|
188
|
-
}
|
|
189
|
-
catch {
|
|
190
|
-
debug.log {
|
|
191
|
-
value = {
|
|
192
|
-
error_name: $error.name,
|
|
193
|
-
error_message: $error.message,
|
|
194
|
-
error_code: $error.code,
|
|
195
|
-
input_data: $data
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Rethrow or handle
|
|
200
|
-
throw {
|
|
201
|
-
name = $error.name
|
|
202
|
-
value = $error.message
|
|
203
|
-
code = $error.code
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Error Recovery
|
|
210
|
-
|
|
211
|
-
```xs
|
|
212
|
-
try_catch {
|
|
213
|
-
try {
|
|
214
|
-
api.request {
|
|
215
|
-
url = $external_api
|
|
216
|
-
timeout = 5000
|
|
217
|
-
} as $response
|
|
218
|
-
}
|
|
219
|
-
catch {
|
|
220
|
-
debug.log {
|
|
221
|
-
value = "External API failed, using fallback"
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
var $response {
|
|
225
|
-
value = {data: [], cached: true}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
## Logging Patterns
|
|
234
|
-
|
|
235
|
-
### Execution Tracing
|
|
236
|
-
|
|
237
|
-
```xs
|
|
238
|
-
function "process_order" {
|
|
239
|
-
input { int order_id }
|
|
240
|
-
stack {
|
|
241
|
-
debug.log { value = "START: process_order(" ~ $input.order_id ~ ")" }
|
|
242
|
-
|
|
243
|
-
db.get order {
|
|
244
|
-
field_name = "id"
|
|
245
|
-
field_value = $input.order_id
|
|
246
|
-
} as $order
|
|
247
|
-
|
|
248
|
-
debug.log { value = "STEP: Fetched order" }
|
|
249
|
-
|
|
250
|
-
function.run "validate_order" {
|
|
251
|
-
input = {order: $order}
|
|
252
|
-
} as $valid
|
|
253
|
-
|
|
254
|
-
debug.log { value = "STEP: Validation result = " ~ $valid }
|
|
255
|
-
|
|
256
|
-
function.run "charge_payment" {
|
|
257
|
-
input = {order: $order}
|
|
258
|
-
} as $payment
|
|
259
|
-
|
|
260
|
-
debug.log { value = "STEP: Payment charged" }
|
|
261
|
-
|
|
262
|
-
debug.log { value = "END: process_order" }
|
|
263
|
-
}
|
|
264
|
-
response = $payment
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### Performance Logging
|
|
269
|
-
|
|
270
|
-
```xs
|
|
271
|
-
var $start_time { value = now|to_ms }
|
|
272
|
-
|
|
273
|
-
// Expensive operation
|
|
274
|
-
db.query large_table {
|
|
275
|
-
return = {type: "all"}
|
|
276
|
-
} as $results
|
|
277
|
-
|
|
278
|
-
var $end_time { value = now|to_ms }
|
|
279
|
-
var $duration { value = $end_time - $start_time }
|
|
280
|
-
|
|
281
|
-
debug.log {
|
|
282
|
-
value = "Query took " ~ $duration ~ "ms, returned " ~ ($results|count) ~ " rows"
|
|
283
|
-
}
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### Conditional Logging
|
|
287
|
-
|
|
288
|
-
```xs
|
|
289
|
-
// Only log in development
|
|
290
|
-
conditional {
|
|
291
|
-
if ($env.DEBUG == "true") {
|
|
292
|
-
debug.log {
|
|
293
|
-
value = $detailed_info
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
|
|
301
|
-
## Database Debugging
|
|
302
|
-
|
|
303
|
-
### Log Query Results
|
|
304
|
-
|
|
305
|
-
```xs
|
|
306
|
-
db.query user {
|
|
307
|
-
where = $db.user.active == true
|
|
308
|
-
} as $users
|
|
309
|
-
|
|
310
|
-
debug.log {
|
|
311
|
-
value = {
|
|
312
|
-
query: "active users",
|
|
313
|
-
count: $users|count,
|
|
314
|
-
first_10: $users|slice:0:10
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
### Log Mutations
|
|
320
|
-
|
|
321
|
-
```xs
|
|
322
|
-
db.add user {
|
|
323
|
-
data = $user_data
|
|
324
|
-
} as $new_user
|
|
325
|
-
|
|
326
|
-
debug.log {
|
|
327
|
-
value = {
|
|
328
|
-
action: "user_created",
|
|
329
|
-
id: $new_user.id,
|
|
330
|
-
data: $user_data
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
---
|
|
336
|
-
|
|
337
|
-
## API Debugging
|
|
338
|
-
|
|
339
|
-
### Log Requests
|
|
340
|
-
|
|
341
|
-
```xs
|
|
342
|
-
debug.log {
|
|
343
|
-
value = {
|
|
344
|
-
api_call: $external_api,
|
|
345
|
-
method: "POST",
|
|
346
|
-
body: $request_body
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
api.request {
|
|
351
|
-
url = $external_api
|
|
352
|
-
method = "POST"
|
|
353
|
-
body = $request_body
|
|
354
|
-
} as $response
|
|
355
|
-
|
|
356
|
-
debug.log {
|
|
357
|
-
value = {
|
|
358
|
-
api_response: $response,
|
|
359
|
-
status: $response.status
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
```
|
|
363
|
-
|
|
364
|
-
### Log Authentication
|
|
365
|
-
|
|
366
|
-
```xs
|
|
367
|
-
debug.log {
|
|
368
|
-
value = {
|
|
369
|
-
auth_info: {
|
|
370
|
-
user_id: $auth.id,
|
|
371
|
-
role: $auth.role,
|
|
372
|
-
ip: $env.$remote_ip
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
---
|
|
379
|
-
|
|
380
|
-
## Debugging Tips
|
|
381
|
-
|
|
382
|
-
### Isolate Problems
|
|
383
|
-
|
|
384
|
-
```xs
|
|
385
|
-
// Add log before suspected issue
|
|
386
|
-
debug.log { value = "Before problematic code" }
|
|
387
|
-
debug.log { value = $suspect_variable }
|
|
388
|
-
|
|
389
|
-
// Problematic code
|
|
390
|
-
function.run "suspect_function" {
|
|
391
|
-
input = $suspect_variable
|
|
392
|
-
} as $result
|
|
393
|
-
|
|
394
|
-
// Add log after
|
|
395
|
-
debug.log { value = "After problematic code" }
|
|
396
|
-
debug.log { value = $result }
|
|
397
|
-
```
|
|
398
|
-
|
|
399
|
-
### Check Variable Types
|
|
400
|
-
|
|
401
|
-
```xs
|
|
402
|
-
debug.log {
|
|
403
|
-
value = {
|
|
404
|
-
value: $variable,
|
|
405
|
-
type: $variable|is_array ? "array"
|
|
406
|
-
: $variable|is_object ? "object"
|
|
407
|
-
: $variable|is_int ? "int"
|
|
408
|
-
: $variable|is_text ? "text"
|
|
409
|
-
: $variable|is_null ? "null"
|
|
410
|
-
: "unknown"
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
```
|
|
414
|
-
|
|
415
|
-
### Log Loop Progress
|
|
416
|
-
|
|
417
|
-
```xs
|
|
418
|
-
var $index { value = 0 }
|
|
419
|
-
|
|
420
|
-
foreach ($items) {
|
|
421
|
-
each as $item {
|
|
422
|
-
var.update $index { value = $index + 1 }
|
|
423
|
-
|
|
424
|
-
conditional {
|
|
425
|
-
if ($index % 100 == 0) {
|
|
426
|
-
debug.log {
|
|
427
|
-
value = "Processed " ~ $index ~ " of " ~ ($items|count)
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
---
|
|
436
|
-
|
|
437
|
-
## Production Debugging
|
|
438
|
-
|
|
439
|
-
### Structured Logging
|
|
440
|
-
|
|
441
|
-
```xs
|
|
442
|
-
db.add log_entry {
|
|
443
|
-
data = {
|
|
444
|
-
level: "error",
|
|
445
|
-
context: "payment_processing",
|
|
446
|
-
message: $error.message,
|
|
447
|
-
data: {
|
|
448
|
-
order_id: $order.id,
|
|
449
|
-
amount: $order.total,
|
|
450
|
-
user_id: $auth.id
|
|
451
|
-
},
|
|
452
|
-
request: {
|
|
453
|
-
method: $env.$request_method,
|
|
454
|
-
uri: $env.$request_uri,
|
|
455
|
-
ip: $env.$remote_ip
|
|
456
|
-
},
|
|
457
|
-
created_at: now
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Error Reporting
|
|
463
|
-
|
|
464
|
-
```xs
|
|
465
|
-
try_catch {
|
|
466
|
-
try {
|
|
467
|
-
// Operation
|
|
468
|
-
}
|
|
469
|
-
catch {
|
|
470
|
-
// Log to database
|
|
471
|
-
db.add error_log {
|
|
472
|
-
data = {
|
|
473
|
-
error_name: $error.name,
|
|
474
|
-
error_message: $error.message,
|
|
475
|
-
error_code: $error.code,
|
|
476
|
-
stack_trace: $error.stack,
|
|
477
|
-
context: "api_endpoint",
|
|
478
|
-
user_id: $auth.id,
|
|
479
|
-
request_data: $input|json_encode,
|
|
480
|
-
created_at: now
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// Alert if critical
|
|
485
|
-
conditional {
|
|
486
|
-
if ($error.code >= 500) {
|
|
487
|
-
util.send_email {
|
|
488
|
-
to = $env.ADMIN_EMAIL
|
|
489
|
-
subject = "Critical Error: " ~ $error.name
|
|
490
|
-
body = $error.message
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// Rethrow
|
|
496
|
-
throw {
|
|
497
|
-
name = $error.name
|
|
498
|
-
value = $error.message
|
|
499
|
-
code = $error.code
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
```
|
|
504
|
-
|
|
505
|
-
---
|
|
506
|
-
|
|
507
|
-
## Disable in Production
|
|
508
|
-
|
|
509
|
-
### Mock Debug Functions
|
|
510
|
-
|
|
511
|
-
```xs
|
|
512
|
-
// Wrapper that respects environment
|
|
513
|
-
conditional {
|
|
514
|
-
if ($env.ENVIRONMENT != "production") {
|
|
515
|
-
debug.log { value = $debug_info }
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
### Using Disabled Flag
|
|
521
|
-
|
|
522
|
-
```xs
|
|
523
|
-
debug.log {
|
|
524
|
-
disabled = $env.ENVIRONMENT == "production"
|
|
525
|
-
value = $sensitive_debug_info
|
|
526
|
-
}
|
|
527
|
-
```
|