Display LSTAT error in sweet way

I am working on a project in my company which relies on log information a lot. I can’t reveal name and working of the system here because it’s company property but it is very complicated and high performance system which log everything it do. In the log there was some error’s coming called “ENOENT” from LSTAT call. My challenge was to dig into it and make this error more descriptive so that the administrator of the System understand the error’s from log.


So i surfed some forums and found nothing much informative, then i look over the man page of LSTAT and there was my answer, every possible error LSTAT can throw is been listed there. My job was then to write few lines of code and that’s it. But while surfing over this issue i figured many people are facing this issue in different way and i thought to make it useful for them too, so i wrote some lines of code and made this Sweet LSTAT node module which is available at npmjs.org

Install SLSTAT:

You can install it using npm command as follows.

npm install lstat

You may require SUDO access in Linux or Mac system.

How to use it:

It have two facility:

  • Show error from error number ( 1,2..)
  • Show error from Code (ENOENT,FD..)

You can use both of it at a time. Let me explain you with this sample code.

var errdetail = require('slstat')
var path="/home/unixroot/Desktop/zookeeper";
fs.lstat(path,function(err,stat){
if(err)
{
//FYI: err is object contains errno, code of error.
console.log(errdetail.getErrorFromNum(err.errno).msg);
console.log(errdetail.getErrorFromCode(err.code).msg);
}
else
{
//Do other task
}
});

In this way if error occurs we can come to know the details about it and also by googling the detail, we can easily determine the cause of an error. I hope this helps many people out there who work on node and find some difficulty in debugging node.

Shahid (UnixRoot) Shaikh

Hey there,

This is Shahid, an Engineer and Blogger from Bombay. I am also an Author and i wrote a programming book on Sails.js, MVC framework for Node.js.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *