Skip to content

Commit 4afbe00

Browse files
committed
Updating text
1 parent 0ae30a1 commit 4afbe00

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

diagnostics/index.md

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,9 @@ author: donovan
55
date: 1903-10-09
66
---
77

8-
Goals of this lesson:
8+
In this lesson we will take a look at ways we can diagnose issues in our code. To do this we'll use the built-in Node.js debugger, as well as the Chrome dev tools.
99

10-
* Learn how to set up Node Debugger
11-
* Step through breakpoints using Repl
12-
* Inspecting in the Chrome debugger
13-
* Explore more powerful debugging options
14-
* Generate diagnostic deports to catch errors
15-
* Finding memory leaks
16-
17-
Pre-requisites:
18-
19-
INTRO and expected outcomes
10+
After this lesson you should be confident investigating errors in a methodical fashion, without relying on `console.log` so much.
2011

2112
## Node.js Debugger
2213

@@ -58,7 +49,7 @@ Wait, I counted too far!
5849

5950
Something has gone wrong! Let's use the debugger tool to find out what.
6051

61-
### debugger;
52+
### The `debugger` command
6253

6354
In the above code you might have noticed the `debugger;` code on line 3. During normal operation this is ignored, but we can make use of this by running `inspect`:
6455

@@ -70,7 +61,7 @@ This will enter `debug` mode where we can use command to inspect what is going o
7061

7162
Firstly we can use `list()` to take a look at the place in the code we are currently exectuting. At first it'll be on line 16 `startACount()`. All good so far. We can then continue using `cont` to continue exectuting until we reach the break point.
7263

73-
By entering the `cont` command we should now see:
64+
By entering the continue (`cont`) command we should now see:
7465

7566
```
7667
1 function count() {
@@ -113,17 +104,6 @@ So we've managed to get to the moment when the script fails. Enter the `repl` co
113104

114105
You can quit the debugger by typing `.exit` or by pressing `Cmd+C` twice.
115106

116-
### Watchers
117-
118-
119-
120-
### Homework
121-
122-
Feel free to try moving the `debugger;` statement around in the above. You can also try using the `help` command in the `debug` mode to see other options.
123-
124-
Try breaking the code and then using the `debug` mode to narrow down the issue. Inspecting variables using the REPL can be helpful to find logic errors or catch situations where variables contain unexpected values.
125-
126-
127107
## Debugging using Node.js with Chrome DevTools
128108

129109
We don't just need the command line to debug our code. We can also make use of Chrome's debugging tools to help navigate our code.
@@ -204,36 +184,18 @@ To create the report, we can run the following command against out `count.js` fi
204184
node --report-uncaught-exception count.js
205185
```
206186

207-
This generates [a report in JSON](/diagnostics/report.20210505.160745.11097.0.001.json) that you can read to try to work out what has happened.
208-
187+
This generates a report in JSON that you can read to try to work out what has happened.
209188

189+
It includes a lots of information on the JavaScript and native stack traces, heap statistics, platform information, resource usage and local environmental variables.
210190

191+
Along with debugging the error messages from the script, this can be helpful in determining the state of the application when an uncaught exception occurred.
211192

212193
With the report option enabled, diagnostic reports can be triggered on unhandled exceptions, fatal errors and user signals, in addition to triggering programmatically through API calls. Read more on the official [diagnostic report docs page](https://nodejs.org/api/report.html).
213194

195+
### Homework
214196

215-
## Async hooks
216-
217-
- A lot of services track everything going on in Node by monkey patching anything that is asynchronous, to keep track of processes over time
218-
- Introducing AsyncHooks from https://github.com/nodejs/diagnostics
219-
220-
* note: don't use console.log inside async_hooks methods as it is asynchronous and will cause infinite `init` calls, instead use `process._rawDebug(msg)`
221-
222-
223-
## Investigating memory leaks
224-
225-
// TODO: create example with a memory leak
226-
227-
```
228-
Monitor values from process.memoryUsage() over time.
229-
```
230-
231-
Make heap snapshots
232-
233-
https://www.npmjs.com/package/heapdump
234-
235-
Compare in chromium/chrome
197+
Feel free to try moving the `debugger;` statement around in the above. You can also try using the `help` command in the `debug` mode to see other options.
236198

237-
// TODO: More on debugging memory leaks
199+
Try breaking the code and then using the `debug` mode to narrow down the issue. Inspecting variables using the REPL can be helpful to find logic errors or catch situations where variables contain unexpected values.
238200

239-
## Summary
201+
Try out the same exercise using the Chrome devtools and see how it differs. By being familiar with each you will find it easier to know what tools to use to debug any issues in future.

0 commit comments

Comments
 (0)