@@ -113,54 +113,7 @@ export function run<T>(id: string, cb: () => T) {
113
113
}
114
114
```
115
115
116
- ## ** Case 1** : Incomplete error stacks
117
-
118
- ``` typescript
119
- window .onload = e => {
120
- // (1)
121
- fetch (" https://example.com" ).then (res => {
122
- // (2)
123
- return processBody (res .body ).then (data => {
124
- doSomething (data );
125
- });
126
- });
127
- };
128
-
129
- function processBody(body ) {
130
- // (3)
131
- return body .json ().then (obj => {
132
- // (4)
133
- return obj .data ;
134
- });
135
- }
136
- ```
137
-
138
- The code snippet above is simple and intuitive. However, if there is one or
139
- other step goes wrong -- not behaving as what we expect, it is hard to root
140
- out the cause of the problem.
141
-
142
- What if the ` fetch ` failed for network issues? In the case, the only error
143
- message we can get in DevTools will be:
144
-
145
- ```
146
- TypeError: Failed to fetch
147
- at rejectPromise
148
- ```
149
-
150
- > V8 introduced [ async stack traces] [ ] not before long:
151
- > ```
152
- > GET https://example.com/ net::ERR_TUNNEL_CONNECTION_FAILED
153
- > window.onload @ (index):13
154
- > load (async)
155
- > (anonymous) @ (index):12
156
- > ```
157
- > This is wonderful, but it's not the story for most other platforms.
158
-
159
- It could be messy for a rather complex project if the error can not be
160
- identified by its error stacks, and more importantly its async cause -- i.e.
161
- where did we get to the error in an async way?
162
-
163
- ## **Case 2**: Where did we come to here?
116
+ ## Determine the initiator of the task
164
117
165
118
``` typescript
166
119
export async function handler(ctx , next ) {
@@ -183,12 +136,11 @@ async function dbQuery(query) {
183
136
In Node.js applications, we can orchestrate many downstream services to provide
184
137
a composite data to users. What the thing is, if the application goes a long
185
138
unresponsive downtime, it can be hard to determine which step in our app caused
186
- the issue. Node.js experimental builtin module ` async_hooks ` can be used to
187
- track and maintain a context across the async flow of the request-response.
188
- However, they are not perfect in
189
- [ cases] ( https://gist.github.com/Qard/faad53ba2368db54c95828365751d7bc ) , and may
190
- get worse while working with ` async ` /` await ` since they are part of the language
191
- and can not be shimmed by third party vendors.
139
+ the issue.
140
+
141
+ Node.js builtin api ` AsyncLocalStorage ` can be used to maitain the async task
142
+ flow of the request-response and retrieve the initiator of the task. However,
143
+ this is not part of the standard and is not available on other runtimes.
192
144
193
145
## Summary
194
146
0 commit comments