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

@pmbservices/pmbstoreerrormanager

v1.0.0

Published

Error handler for all modules of PMBStore

Downloads

2

Readme

PMBStore ErrorManager

PMBStore ErrorManager is used to throw errors by others module with usefull information.

How to use the ErrorManager in others modules

Just require ErrorManager in each class file of the module:

const ErrorManager=require('ErrorManager');

Then when you want to throw an error call throw static method :

ErrorManager.throw(code,[e],[options]);

code is the code of the error defined in the file errorsDef.json, e is optional and may be the error catched who lead you to throw this error, options is an object containing properties to replace in the message defined in errorsDef.json (see below).

the file errorsDef.json

It must contain an object with properties that have the same name as the class names in the module. The value associated with each property is on object containing properties for each code and an associated a message. In the message you can put some variables name between '%' that will be replaced when the error is thrown.

Example

If you have 2 classes Disk and Record in a PMBStoreDisk module that can throw errors, then create an errorsDef.json containing :

{
    "Disk":{
        "CantOpenRW":"Can't open disk %disk% in read/write mode",
        "Read":"Read error at position %position%",
        "NoPath":"Please provide path of the disk"
    },
    "Record":{
        "BadHeader":"Header of the record is not constitent",
    }
}

The PMBStoreError error class

This class extends the javascript Error class. The nameproperty is the code of the error and message the message in errorsDef.json with variables substituted by the properties of the options object. It has also specific fields :

  • jsclass: the class of the module who thrown this error
  • module: the module of PMBStore from where this error where thrown
  • eOrigin: the original error catched by the module who led to throw this error
  • options: the options object who contain the variables value of the message. You may also put extra properties that you need to manage this error

Example

e is the error thrown by fs.openSync

ErrorManager.throw('CantOpenRW',e,{
    "disk":"/dev/sdb"
});

will throw a PMBStoreError object like this :

PMBStoreError {
    name:"CantOpenRW",
    message:"Can't open disk /dev/sdb in read/write mode",
    jsclass:"Disk",
    module:"pmbstoredisk",
    eOrigin:e, //error thrown by fs.openSync
    options:{
        "disk":"/dev/sdb"
    }
}