https://github.com/diokuz/syntax-error-stack
Just better syntax error log for nodejs.
https://github.com/diokuz/syntax-error-stack
callstack error-handling nodejs syntax
Last synced: 10 months ago
JSON representation
Just better syntax error log for nodejs.
- Host: GitHub
- URL: https://github.com/diokuz/syntax-error-stack
- Owner: Diokuz
- Created: 2019-02-12T07:48:28.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-11T10:35:56.000Z (about 6 years ago)
- Last Synced: 2025-01-04T23:22:08.034Z (12 months ago)
- Topics: callstack, error-handling, nodejs, syntax
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Just better syntax error log for nodejs.
## Example
a.js
```js
require('./b')
```
b.js
```js
! some invalid js, await async yield debugger
```
### CLI
> it is ignoring ts, tsx, jsx and css file extensions by default
```
yarn ses examples/simple/a.js
yarn run v1.17.3
$ bin/ses.js examples/simple/a.js
entry: /Users/d.o.kuznetsov/github/syntax-error-stack/examples/simple/a.js
filename /Users/d.o.kuznetsov/github/syntax-error-stack/examples/simple/a.js
filename /Users/d.o.kuznetsov/github/syntax-error-stack/examples/simple/b.js
Total files number: 2
Total loads: 2
Bad require chain #1
→ /Users/d.o.kuznetsov/github/syntax-error-stack/examples/simple/b.js
...
```
### JS API
> is not ignoring any extensions by default, use require-hacker or something else
index.js
```js
const ses = require('syntax-error-stack')
ses(require.resolve('./a'))
```
The result log will be:
```
$ node examples/simple/index.js
Bad require chain #1
→ /Users/xxx/github/syntax-error-stack/examples/simple/b.js
→ /Users/xxx/github/syntax-error-stack/examples/simple/a.js
→ /Users/xxx/github/syntax-error-stack/index.js
→ .
/Users/xxx/github/syntax-error-stack/examples/simple/b.js:1
(function (exports, require, module, __filename, __dirname) { ! some invalid js, await async yield debugger
^^^^^^^
```
## Explanation
You can have a huge dependency tree, and only one bad file. It is important to extract not only filename, but full require chain.
`syntax-error-stack` uses non-stable API `Module._compile` and `Module._extensions` – same is used in `require-hacker` module. So, each js-file require is actually wrapped with custom function, which, in case of compile problems, stores errors and full require chains for log.
See `/index.js` for details – it is not too big/hard to read and understand.
Also, you could easily count the total number of files in your dependency tree, and list them all via CLI.