npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

errawr

v0.1.1

Published

Build with better errors! Rawr!

Downloads

3

Readme

Errawr!

Errawr is indubitably the cutest library to help you get help from your errors. It prints semi-structured messages, which is to say that its output is meant to be somewhere in between natural language and JSON. This is particularly freeing because constructing error messages that always read like natural language is a) hard, and b) pointless. A semi-structured approach also makes errors far easier to write and read errors occur due to issues which are difficult to print, like empty strings where non-empty strings are expected, and even errors which arise from unprintable characters.

The project is inspired by the error.cause feature of the Ecmascript spec as well as a few existing packages, namely verror, nerror, and pupa. Its printing is done by object-inspect.

Errawr is unrelated to the Ruby package of the same (excellent) name.

Usage

import Errawr, { rawr, invariant } from 'errawr';

function rave(system) {
  invariant(system.status === 'up', rawr('The system is {system.status}'), { system });

  return '200 SBEMAILS';
}

export default function main() {
  try {
    rave({ status: 'down' });
  } catch(e) {
    // stringify your errors as far up the call stack as is possible.
    console.error(Errawr.print(e));

    /*
    Error: The system is {status: 'down'}
    at rave:4:2
    at main:11:4
    */
  }
}

The above example uses the invariant shorthand, which is equivalent to:

if (system.status !== 'up') {
  throw new Errawr(rawr('The system is {system.status}'), {
    info: { system },
  });
}

If you don't need or want templating you can always omit rawr. Note that it may still be useful to provide relevant info: though it won't end up in the logs it will still be visible to you while debugging.

new Errawr('The system is not up', { info: { system } });

Differences with VError

If you're already familiar with VError, here's what's changed:

  • new VError(options, 'reason') has become new Errawr('reason', options)
  • verror.cause() is now errawr.cause (i.e. not a function). This aligns with the new spec.
  • There is no MultiError. Instead use the builtin AggregateError.
  • There is no distinction between VError and SError. Presentation details have no place at the bottom of a class hierarchy. Instead you should handle message interpolation yourself. You may use the provided rawr function to do basic interpolation.
  • VError.fullStack(error) is Errawr.print(error)
  • causes are now in now an iterable returned from Errawr.chain(err)
    • Instead of VError.findCauseByName(err) use find(hasName(name, cause), Errawr.chain(err))
    • Instead of VError.hasCauseWithName(err) use some(hasName(name, cause), Errawr.chain(err))
    • find or some methods are provided by your favorite iterator tools.
  • constructorFn is now called topFrame
  • There is no strict mode. Serialization of interpolated values is best-effort.