|
1 | 1 | # ts-error-handler |
2 | 2 |
|
3 | | -## Development |
| 3 | +This package enhances typescript error handling, meaning easier troubleshooting and debugging! |
4 | 4 |
|
5 | | -Run a dev test with `npm start` |
| 5 | +- Source mapping |
| 6 | +- Customizable stack traces |
| 7 | +- Set stack trace limit |
| 8 | +- Set stack trace to "Just my Code" |
| 9 | +- Sets global uncaught global error handlers |
6 | 10 |
|
7 | | -## Running Tests |
| 11 | +## Setup |
8 | 12 |
|
9 | | -To run unit tests, `npm run test` |
| 13 | +**Install** |
10 | 14 |
|
11 | | -## Compiling |
| 15 | +`npm i ts-error-handler` |
12 | 16 |
|
13 | | -### Debug Builds |
| 17 | +**Usage** |
14 | 18 |
|
15 | | -To compile a debug build, run `npm run build:dev`. The build output will appear in the `./dist` folder. |
| 19 | +```typescript |
| 20 | +import { setupErrorHandling } from 'ts-error-handler'; |
16 | 21 |
|
17 | | -### Prod Builds |
| 22 | +// Setup error handling options |
| 23 | +setupErrorHandling({ |
| 24 | + justMyCode: true, |
| 25 | + handler: (e) => console.error('Error!', e) |
| 26 | +}) |
18 | 27 |
|
19 | | -To compile a production build, run `npm run build:prod`. The build output will appear in the `./dist` folder. |
| 28 | +// Example: |
| 29 | +throw new Error('Help!'); |
| 30 | +``` |
20 | 31 |
|
21 | | -### Clean Builds |
| 32 | +**With ts-async-bootstrap** |
22 | 33 |
|
23 | | -To generate a clean build (removes old artifacts and reruns pre&post process scripts), append `:clean` to a build script: |
24 | | -- Debug: `npm run build:dev:clean` |
25 | | -- Release: `npm run build:prod:clean` |
| 34 | +```typescript |
| 35 | +import { bootstrap } from 'ts-async-bootstrap'; |
| 36 | +import { setupErrorHandling } from 'ts-error-handler'; |
26 | 37 |
|
27 | | -## More |
| 38 | +import { register, main } from './somewhere-else'; |
28 | 39 |
|
29 | | -### Generating Docs |
| 40 | +function errorHandler(e: Error): void { |
| 41 | + console.error('Error!', e); |
| 42 | +} |
30 | 43 |
|
31 | | -`npm run doc` and browse docs/index.html! |
| 44 | +// Setup error handling |
| 45 | +setupErrorHandling({ |
| 46 | + handler: errorHandler |
| 47 | +}); |
| 48 | + |
| 49 | +// Pass handler from ts-error-handler to bootstrap() |
| 50 | +bootstrap({ |
| 51 | + register: register, |
| 52 | + run: main, |
| 53 | + errorHandler: errorHandler |
| 54 | +}); |
| 55 | +``` |
32 | 56 |
|
33 | | -### Environment Variables |
| 57 | +## Options |
34 | 58 |
|
35 | | -Environment variables should be set in .env |
36 | 59 |
|
37 | | -To add additional environment variables, edit `src/environment.ts`: |
| 60 | +**traceLimit** |
38 | 61 |
|
39 | | -```typescript |
40 | | -/** |
41 | | - * Environment Variables Schema |
42 | | - */ |
43 | | -export interface Environment { |
44 | | - APP_TITLE: string |
| 62 | +Set how long the stack trace is, in lines. Default is 100 |
45 | 63 |
|
46 | | - // TODO: Add additional allowed variables |
47 | | -} |
| 64 | +**justMyCode** |
48 | 65 |
|
49 | | -/** |
50 | | - * Default Values |
51 | | - */ |
52 | | -const defaults: Environment = { |
53 | | - APP_TITLE: 'ts-error-handler' |
| 66 | +Set to true to show only local code in stack traces (no node-modules or node-internals) |
54 | 67 |
|
55 | | - // TODO: Set default variables here |
56 | | -}; |
57 | | -``` |
| 68 | +**justMyCodeIncludeNodeModules** |
| 69 | + |
| 70 | +Set to true to show node-modules in stack traces when justMyCode is on |
| 71 | + |
| 72 | +**justMyCodeIncludeInternals** |
| 73 | + |
| 74 | +Set to true to show node-internals in stack traces when justMyCode is on |
| 75 | + |
| 76 | +**handler** |
| 77 | + |
| 78 | +Global error handler for uncaught exceptions/promise-rejections. Default is `console.error` |
0 commit comments