Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

erotic

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

erotic

Capture synchronous part of the error stack in asynchronous functions

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
177
decreased by-38.33%
Maintainers
1
Weekly downloads
 
Created
Source

Erotic

erotic

erotic is a Node.js module to capture asynchronous stack traces.

You create a callback function by calling erotic() at the point where you want you stack trace to start from. Then, in an asynchronous function you call this the callback either with a message string or an Error object. The stack trace will be updated to include the point of entry.

Start using erotic npm package today to get the benefits of more user-friendly error messages from asynchronous function calls.

ES5

The package uses some newer language features. For your convenience, it's been transpiled to be compatible with Node 4. You can use the following snippet.

const erotic = require('erotic/es5/src/')

API

The package's API consists of 2 functions: a constructor of a callback, which should be used when the error stack trace should start, and the callback which should be called in the asynchronous function.

erotic

function(): callback

Constructor for the error, where the stack trace will begin from.

import erotic from 'erotic'

function example() {
    const callback = erotic()
}

example()

callback

function(messageOrError: (string|Error)): Error

The callback to get the error with the stack which includes the constructor line.

import erotic from 'erotic'

function example() {
    const callback = erotic()
    setTimeout(() => {
        const error = callback('some error')
        // or
        // const error = callback(new Error('some error'))
        throw error
    }, 10)
}

example()
/example/erotic.js:6
        throw err('some error')
        ^

Error: some error
    at Timeout.setTimeout [as _onTimeout] (/example/erotic.js:6:15)
    at example (/example/erotic.js:4:17)
    at Object.<anonymous> (/example/erotic.js:10:1)

Using with Promises

One of the most common use cases is with promises. You can call erotic function at your entry line, and reject a promise with an error created with the callback.

async function exampleWithPromise() {
    const err = erotic()
    await new Promise((_, reject) => {
        setTimeout(() => {
            const error = err('promise timeout error')
            reject(error)
        }, 10)
    })
}

(async () => {
    await exampleWithPromise()
})()
Error: promise timeout error
    at Timeout.setTimeout [as _onTimeout] (/Users/anton/Sobes/erotic/example/erotic.js:30:27)
    at exampleWithPromise (/Users/anton/Sobes/erotic/example/erotic.js:27:17)
    at __dirname (/Users/anton/Sobes/erotic/example/erotic.js:56:11)
    at Object.<anonymous> (/Users/anton/Sobes/erotic/example/erotic.js:57:3)

Motivation

If erotic is not used, then the entry point to the async execution will not be recorded in the error stack, and Node internals are exposed:

function example() {
    setTimeout(() => {
        throw err('some error')
    }, 10)
}
/example/node.js:3
        throw new Error('some error')
        ^

Error: some error
    at Timeout.setTimeout [as _onTimeout] (/example/node.js:3:15)
    at ontimeout (timers.js:469:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:264:5)

Logo: Thornton’s Temple of Flora

(c) Sobesednik-Media 2017

Keywords

FAQs

Package last updated on 19 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc