What is errno?
The errno npm package provides a convenient way to create, manage, and interact with system-level errors in Node.js applications. It allows developers to easily look up error codes and create custom errors that integrate seamlessly with Node.js's error handling mechanisms.
What are errno's main functionalities?
Creating custom errors
This feature allows developers to create custom errors. The code sample demonstrates how to create a new custom error type called 'MyError' and then instantiate an error of this type.
const create = require('errno').create;
const MyError = create('MyError');
const err = new MyError('An error occurred');
Looking up error codes
This feature enables developers to look up error codes by their common names. The code sample shows how to access the properties of the 'errno.code' object to find information about the 'ENOENT' error code.
const errno = require('errno');
console.log(errno.code.ENOENT);
Other packages similar to errno
verror
Verror is a package that provides a way to create rich JavaScript errors. It is similar to errno in that it enhances error handling in Node.js applications, but it focuses more on providing a framework for annotating errors than on integrating with system-level errors.
error
The 'error' package offers a simple way to create custom errors in Node.js, similar to errno's functionality for creating custom errors. However, it does not provide the same level of integration with system-level error codes.
node-errno
libuv errno details exposed. Available in npm as errno
Ever find yourself needing more details about NodeJS errors? Me too, so node-errno contains the errno mappings direct from libuv so you can use them in your code.
By errno:
require('errno').errno[3]
By code:
require('errno').code.ENOTEMPTY
Make your errors more descriptive:
var errno = require('errno')
function errmsg(err) {
var str = 'Error: '
if (errno.errno[err.errno]) {
str += errno.errno[err.errno].description
} else {
str += err.message
}
if (err.path) {
str += ' [' + err.path + ']'
}
return str
}
var fs = require('fs')
fs.readFile('thisisnotarealfile.txt', function (err, data) {
if (err)
return console.log(errmsg(err))
})
Copyright (c) 2012 Rod Vagg (@rvagg)
Made available under the MIT licence:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.