New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

pinocchio

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pinocchio

my error handling library

latest
Source
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

Pinocchio

...is a real Error.

Born out of frustration at certain libraries returning "errors" that were actually strings (sometimes plain and sometimes as JSON blobs) or vanilla objects, this library takes just about anything passed to it and turns it into something that is instanceof Error.

Because hey, better late than never.

Example:

example.js:

var pinocchio = require('./');

var str, json, halfJson, obj;

//
// It works on strings!
//
str = 'That\'s not an error!';
console.log(pinocchio(str));

//
// It's smart about JSON strings...
//
json = JSON.stringify({
  code: 200,
  message: 'a JSON string with a message'
});
console.log(pinocchio(json));

//
// ...and handles some embedded JSON strings too
//
halfJson = 'I\'M HELPING!! ' + JSON.stringify({ payload: 'ponyyyyyy' });
console.log(pinocchio(halfJson));

//
// Of course, it can also handle vanilla objects
//
obj = { code: 404, message: 'not_found'};

//
// We can also get a little passive-aggressive here (or clarify what the code
// is doing, either way)
//
console.log(pinocchio.isARealError(obj));

log.log:

josh@onix:~/dev/pinocchio$ node example.js 
{ [Error: That's not an error!] fails: [ 'is a string' ] }
{ [Error: a JSON string with a message]
  code: 200,
  fails: [ 'is a string', 'is a JSON-encoded string' ] }
{ [Error: I'M HELPING!! {"payload":"ponyyyyyy"}]
  payload: 'ponyyyyyy',
  fails: [ 'is a string', 'is a string with a JSON fragment inside it' ] }
{ [Error: not_found] code: 404, fails: [ 'is a non-error object' ] }

License:

MIT

Keywords

error

FAQs

Package last updated on 15 Aug 2021

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