[ PROMPT_NODE_24692 ]
stack-trace
[ SKILL_DOCUMENTATION ]
# 堆栈跟踪分析指南
如何阅读和分析跨不同语言的堆栈跟踪。
## 堆栈跟踪的解剖
堆栈跟踪显示了导致错误的调用序列:
Error: Something went wrong
at functionC (file3.js:10:5) <- 错误在此处抛出
at functionB (file2.js:20:3) <- 被 functionB 调用
at functionA (file1.js:30:7) <- 被 functionA 调用
at main (index.js:5:1) <- 入口点
**阅读顺序**: 顶部 = 错误发生处,底部 = 入口点
## JavaScript/Node.js 堆栈跟踪
### 标准格式
TypeError: Cannot read property 'name' of undefined
at getUser (/app/src/services/user.js:45:23)
at async handler (/app/src/routes/api.js:12:18)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:144:13)
**组件**:
- `TypeError` - 错误类型
- `Cannot read property 'name' of undefined` - 错误消息
- `/app/src/services/user.js:45:23` - 文件:行:列
- `getUser` - 函数名
- `async handler` - 异步函数指示器
### 关键模式
**用户代码 vs 框架**:
at getUser (/app/src/services/user.js:45:23) <- 你的代码
at handler (/app/src/routes/api.js:12:18) <- 你的代码
at Layer.handle [as handle_request] (express/...) <- 框架
at next (express/lib/router/route.js:144:13) <- 框架
优先关注你代码中的帧。
**匿名函数**:
at Object. (/app/index.js:5:1)
at Array.forEach ()
at /app/src/utils.js:10:5
添加函数名以获得更好的跟踪信息:
javascript
// 代替
const handler = () => { ... }
// 使用
const handler = function userHandler() { ... }
**异步堆栈跟踪** (Node.js 12+):
Error: Failed
at fetchData (/app/src/api.js:10:9)
at async main (/app/src/index.js:5:3)
// -- 异步间隙 --
at Object. (/app/src/index.js:1:1)
启用: `node --async-stack-traces app.js`
---
## Python 堆栈跟踪
### 标准格式 (Traceback)
python
Traceback (most recent call last):
File "/app/main.py", line 10, in
result = process_data(data)
File "/app/processor.py", line 25, in process_data
return transform(data['items'])
File "/app/transformer.py", line 15, in transform
return [parse(item) for item in items]
File "/app/transformer.py", line 15, in
return [parse(item) for