Skip to content

Commit d943910

Browse files
authored
Merge pull request #1 from StatelessStudio/v1.0.0
V1.0.0
2 parents 3c13054 + 39c80f3 commit d943910

File tree

8 files changed

+209
-131
lines changed

8 files changed

+209
-131
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
# ts-error-handler
2+
3+
## [1.0.0]
4+
5+
Initial release

README.md

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,78 @@
11
# ts-error-handler
22

3-
## Development
3+
This package enhances typescript error handling, meaning easier troubleshooting and debugging!
44

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
610

7-
## Running Tests
11+
## Setup
812

9-
To run unit tests, `npm run test`
13+
**Install**
1014

11-
## Compiling
15+
`npm i ts-error-handler`
1216

13-
### Debug Builds
17+
**Usage**
1418

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';
1621

17-
### Prod Builds
22+
// Setup error handling options
23+
setupErrorHandling({
24+
justMyCode: true,
25+
handler: (e) => console.error('Error!', e)
26+
})
1827

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+
```
2031

21-
### Clean Builds
32+
**With ts-async-bootstrap**
2233

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';
2637

27-
## More
38+
import { register, main } from './somewhere-else';
2839

29-
### Generating Docs
40+
function errorHandler(e: Error): void {
41+
console.error('Error!', e);
42+
}
3043

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+
```
3256

33-
### Environment Variables
57+
## Options
3458

35-
Environment variables should be set in .env
3659

37-
To add additional environment variables, edit `src/environment.ts`:
60+
**traceLimit**
3861

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
4563

46-
// TODO: Add additional allowed variables
47-
}
64+
**justMyCode**
4865

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)
5467

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`

package-lock.json

Lines changed: 24 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-error-handler",
3-
"version": "0.0.0",
3+
"version": "1.0.0",
44
"ts-project-version": "1.2.4",
55
"private": "true",
66
"scripts": {
@@ -28,7 +28,7 @@
2828
"devDependencies": {
2929
"@istanbuljs/nyc-config-typescript": "^1.0.2",
3030
"@types/jasmine": "^3.10.3",
31-
"@types/node": "^12.20.41",
31+
"@types/node": "^12.20.42",
3232
"@typescript-eslint/eslint-plugin": "^4.33.0",
3333
"@typescript-eslint/parser": "^4.33.0",
3434
"coveralls": "^3.1.1",
@@ -37,7 +37,7 @@
3737
"nyc": "^15.1.0",
3838
"ts-node": "^10.4.0",
3939
"ts-packager": "^1.0.1",
40-
"typedoc": "^0.21.9",
40+
"typedoc": "^0.22.11",
4141
"typescript": "^4.5.4"
4242
}
4343
}

src/handler-function.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* A handler function takes an Error and returns void
3+
*/
4+
export type HandlerFunction = (e: Error) => void;

0 commit comments

Comments
 (0)