{"_id":"usererror","_rev":"11-a33e77198427a7941512fbe9e9ebc449","name":"usererror","description":"A base class for V8 JavaScript errors","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"author":{"name":"Michael Jackson","email":"mjijackson@gmail.com"},"name":"usererror","description":"A base class for V8 JavaScript errors","version":"1.0.0","repository":{"type":"git","url":"git://github.com/mjijackson/usererror.git"},"main":".","scripts":{"test":"vows test.js"},"engines":{"node":"~0.4.7"},"dependencies":{},"devDependencies":{"vows":"~0.5.9"},"_npmUser":{"name":"mjijackson","email":"mjijackson@gmail.com"},"_id":"usererror@1.0.0","_engineSupported":true,"_npmVersion":"1.0.103","_nodeVersion":"v0.4.7","_defaultsLoaded":true,"dist":{"shasum":"c30be33ada1561d5f9073467406030d7c1209316","tarball":"https://registry.npmjs.org/usererror/-/usererror-1.0.0.tgz","integrity":"sha512-9Q2FYvGW/gsFYo4HuZxSnADGUc8MIwKX56ua0G0PPkUp2308GtTXa4wvJiJyo7WHluQRah+ZP0YGUkrsn5yc7w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGXIzqTXiidyVsoWtHme/3OG5jEa99Tg8hlG2YcQNRepAiEAr1q45doVaQsYfWdGWJQqNUrKJWP74SF9c8l/st6YEnU="}]},"maintainers":[{"name":"mjijackson","email":"mjijackson@gmail.com"}]},"1.0.1":{"author":{"name":"Michael Jackson","email":"mjijackson@gmail.com"},"name":"usererror","description":"A base class for V8 JavaScript errors","version":"1.0.1","repository":{"type":"git","url":"git://github.com/mjijackson/usererror.git"},"main":"./usererror.js","scripts":{"test":"vows usererror_test.js"},"engines":{"node":">=0.4.7"},"dependencies":{},"devDependencies":{"vows":"~0.5.9"},"_npmUser":{"name":"mjijackson","email":"mjijackson@gmail.com"},"_id":"usererror@1.0.1","_engineSupported":true,"_npmVersion":"1.0.105","_nodeVersion":"v0.6.1","_defaultsLoaded":true,"dist":{"shasum":"4262166bc7253ee1b385d59d4f678ea151327b2e","tarball":"https://registry.npmjs.org/usererror/-/usererror-1.0.1.tgz","integrity":"sha512-N0njg4kUfQia83gytDbBcUmSWMQtgFaaelMZpZxVOXbwXDxg9xsoxIHFBTyc6PUC6LNS3kzMwDK+ghmbRKBYYQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDu/noXZ09VTEh56cSDudj/0lK+SsifjZh5RExH8iZAygIhAJXLQC1wbqvXbUMfccJr7wkL74TmiKTIt1G6dhAoFxo/"}]},"maintainers":[{"name":"mjijackson","email":"mjijackson@gmail.com"}]},"1.0.2":{"author":{"name":"Michael Jackson","email":"mjijackson@gmail.com"},"name":"usererror","description":"A base class for V8 JavaScript errors","version":"1.0.2","repository":{"type":"git","url":"git://github.com/mjijackson/usererror.git"},"main":"./user-error.js","scripts":{"test":"mocha"},"engines":{"node":">=0.4.7"},"dependencies":{},"devDependencies":{"mocha":"1.5.0"},"readme":"[![build status](https://secure.travis-ci.org/mjijackson/usererror.png)](http://travis-ci.org/mjijackson/usererror)\n\nUserError: Because JavaScript errors could be a lot more useful.\n\nThis package provides a base constructor (i.e. \"class\") that makes JavaScript\nerrors on V8 a lot more useful. Errors built using this class have the following\nbenefits:\n\n  - They are easily subclassed\n  - They are nestable (see below)\n\n## Installation\n\nInstall this package using [npm](http://npmjs.org):\n\n    $ npm install usererror\n\nYou are also free to [browse or download the source](https://github.com/mjijackson/error).\n\n## Usage\n\nThe simplest usage for this class is:\n\n```javascript\nvar UserError = require('usererror');\n\ntry {\n  throw new UserError('Kaboom!');\n} catch (e) {\n  console.log(e.message);\n}\n```\n\nErrors are nestable, so an error can have a reference to another error that\ncaused it. This is useful when you'd like to throw a high level error that was\nactually caused by some lower level error. The error that was the cause is used\nas the second argument to the constructor.\n\nIn the example below, we define our own error class `LoginFailedError` that\ninherits from `UserError`. An instance of this class is passed to the\n`loginUser` callback when it fails for some reason. Inside `loginUser` we try\nand connect to the database. In reality, we could be doing any number of things\nthat may ultimately cause an error (e.g. reading from a flat file of user data,\nvalidating the user id, etc.). However, we want callers to know that `loginUser`\nwill always return a `LoginFailedError` if it fails, and not some other error.\n\nThe solution is to wrap any other error in a `LoginFailedError` before passing\nit back up the callback chain. This allows us to preserve the full stack trace\nof the error (in the `fullStack` property) while giving callers a reasonable\nexpectation for what class(es) of errors they can expect.\n\nNote: The `stack` property still works as you would expect, and only contains\nthe stack trace for the error one level deep.\n\n```javascript\nvar util = require('util');\nvar UserError = require('usererror');\n\nfunction LoginFailedError(cause) {\n  UserError.call(this, 'Login failed', cause);\n}\n\nutil.inherits(LoginFailedError, UserError);\n\nfunction loginUser(userId, callback) {\n  connectToDatabase(function (err, db) {\n    if (err) {\n      callback(new LoginFailedError(err));\n    }\n\n    // Login the user.\n  });\n}\n\nloginUser(myUserId, function (err) {\n  console.log(err.fullStack); // Recursive stack trace.\n  console.log(err.stack); // Single-level stack trace.\n});\n```\n\n## License\n\nCopyright 2011 Michael Jackson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nThe software is provided \"as is\", without warranty of any kind, express or\nimplied, including but not limited to the warranties of merchantability,\nfitness for a particular purpose and non-infringement. In no event shall the\nauthors or copyright holders be liable for any claim, damages or other\nliability, whether in an action of contract, tort or otherwise, arising from,\nout of or in connection with the software or the use or other dealings in\nthe software.\n","_id":"usererror@1.0.2","dist":{"shasum":"652798c34da98dbf108b543b953aadd3db85db74","tarball":"https://registry.npmjs.org/usererror/-/usererror-1.0.2.tgz","integrity":"sha512-xvKLSOFpTEQ+x9KIXK/k4TSAsGeMybcB0Fyhu37pKGGEf839oup2IW13tnLn8KRu7pYJCN+3Zq+v7QRCZ2jlPw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAmdeerTvbIsO6Dx3r+UA4WvhRS3VHHnbNPK7oL8YdgoAiBuqnfYXZdAatW0sq79pKujvVlKIt+lqi2wMRhAEUzFLA=="}]},"_npmVersion":"1.1.59","_npmUser":{"name":"mjackson","email":"mjijackson@gmail.com"},"maintainers":[{"name":"mjackson","email":"mjijackson@gmail.com"}]}},"maintainers":[{"name":"mjackson","email":"mjijackson@gmail.com"}],"time":{"modified":"2022-06-28T06:52:28.284Z","created":"2011-10-31T02:29:04.229Z","1.0.0":"2011-10-31T02:30:26.671Z","1.0.1":"2011-11-16T19:05:50.570Z","1.0.2":"2012-10-07T05:28:01.784Z"},"author":{"name":"Michael Jackson","email":"mjijackson@gmail.com"},"repository":{"type":"git","url":"git://github.com/mjijackson/usererror.git"}}