Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# ts-error-handler

## [1.0.0]

Initial release
91 changes: 56 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,78 @@
# ts-error-handler

## Development
This package enhances typescript error handling, meaning easier troubleshooting and debugging!

Run a dev test with `npm start`
- Source mapping
- Customizable stack traces
- Set stack trace limit
- Set stack trace to "Just my Code"
- Sets global uncaught global error handlers

## Running Tests
## Setup

To run unit tests, `npm run test`
**Install**

## Compiling
`npm i ts-error-handler`

### Debug Builds
**Usage**

To compile a debug build, run `npm run build:dev`. The build output will appear in the `./dist` folder.
```typescript
import { setupErrorHandling } from 'ts-error-handler';

### Prod Builds
// Setup error handling options
setupErrorHandling({
justMyCode: true,
handler: (e) => console.error('Error!', e)
})

To compile a production build, run `npm run build:prod`. The build output will appear in the `./dist` folder.
// Example:
throw new Error('Help!');
```

### Clean Builds
**With ts-async-bootstrap**

To generate a clean build (removes old artifacts and reruns pre&post process scripts), append `:clean` to a build script:
- Debug: `npm run build:dev:clean`
- Release: `npm run build:prod:clean`
```typescript
import { bootstrap } from 'ts-async-bootstrap';
import { setupErrorHandling } from 'ts-error-handler';

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

### Generating Docs
function errorHandler(e: Error): void {
console.error('Error!', e);
}

`npm run doc` and browse docs/index.html!
// Setup error handling
setupErrorHandling({
handler: errorHandler
});

// Pass handler from ts-error-handler to bootstrap()
bootstrap({
register: register,
run: main,
errorHandler: errorHandler
});
```

### Environment Variables
## Options

Environment variables should be set in .env

To add additional environment variables, edit `src/environment.ts`:
**traceLimit**

```typescript
/**
* Environment Variables Schema
*/
export interface Environment {
APP_TITLE: string
Set how long the stack trace is, in lines. Default is 100

// TODO: Add additional allowed variables
}
**justMyCode**

/**
* Default Values
*/
const defaults: Environment = {
APP_TITLE: 'ts-error-handler'
Set to true to show only local code in stack traces (no node-modules or node-internals)

// TODO: Set default variables here
};
```
**justMyCodeIncludeNodeModules**

Set to true to show node-modules in stack traces when justMyCode is on

**justMyCodeIncludeInternals**

Set to true to show node-internals in stack traces when justMyCode is on

**handler**

Global error handler for uncaught exceptions/promise-rejections. Default is `console.error`
117 changes: 24 additions & 93 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-error-handler",
"version": "0.0.0",
"version": "1.0.0",
"ts-project-version": "1.2.4",
"private": "true",
"scripts": {
Expand Down Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/jasmine": "^3.10.3",
"@types/node": "^12.20.41",
"@types/node": "^12.20.42",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"coveralls": "^3.1.1",
Expand All @@ -37,7 +37,7 @@
"nyc": "^15.1.0",
"ts-node": "^10.4.0",
"ts-packager": "^1.0.1",
"typedoc": "^0.21.9",
"typedoc": "^0.22.11",
"typescript": "^4.5.4"
}
}
4 changes: 4 additions & 0 deletions src/handler-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* A handler function takes an Error and returns void
*/
export type HandlerFunction = (e: Error) => void;
Loading