Skip to content

virtax/stack-trace-fixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stack-trace-fixer

Modify Node.js error stack traces to display relative paths. That will be especially useful with Docker for navigating source code from the container's stack trace.

Stack trace example without fixer:

app-1  | TypeError: this.model.find is not a function
app-1  |     at CustomerService.find (/home/node/app/src/services/CustomerService.ts:10:29)
app-1  |     at <anonymous> (/home/node/app/src/routes/customerRouter.ts:50:45)
app-1  |     at Layer.handle [as handle_request] (/home/node/app/node_modules/express/lib/router/layer.js:95:5)

Stack trace example with fixer and relative paths:

app-1  | TypeError: this.model.find is not a function
app-1  |     at CustomerService.find (./src/services/CustomerService.ts:10:29)
app-1  |     at <anonymous> (./src/routes/customerRouter.ts:50:45)
app-1  |     at Layer.handle [as handle_request] (./node_modules/express/lib/router/layer.js:95:5)

Usage:

  1. Install
import { installFix, uninstallFix } from 'stack-trace-fixer';
installFix();

You can optionally provide 'pwd' parameter to installFix(), if process.env.PWD (or process.env.INIT_CWD on Windows) is not set.

  1. Catch and log an error
try {
  throw new Error('Test error');
} catch (error) {
  console.error(error.stack)
}

Your error.stack contains relative paths now, so you can easily navigate to the source code from the container.

  1. You can also optionally use the 'uninstallFix' function to remove the fix.
uninstallFix();

About

Modify Node.js error stack traces to display relative paths in a Docker container

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published