{"_id":"error-provider","_rev":"680497","name":"error-provider","description":"Manages errors for third-party modules","dist-tags":{"latest":"0.0.6"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"time":{"modified":"2021-08-30T02:35:10.000Z","created":"2013-01-20T17:19:03.455Z","0.0.6":"2013-03-10T00:17:57.063Z","0.0.5":"2013-03-05T12:12:17.916Z","0.0.4":"2013-03-01T07:54:08.168Z","0.0.3":"2013-02-27T18:28:44.677Z","0.0.2":"2013-01-20T17:19:03.455Z"},"users":{},"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"versions":{"0.0.6":{"name":"error-provider","version":"0.0.6","description":"Manages errors for third-party modules","keywords":["error","errno","provider","libuv"],"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"engines":{"node":"*"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.html"}],"main":"lib/error-provider","readmeFilename":"README.md","_id":"error-provider@0.0.6","dist":{"shasum":"37936c7a76c86afaec74af0f2542b9f5bee306b0","size":4200,"noattachment":false,"key":"/error-provider/-/error-provider-0.0.6.tgz","tarball":"http://registry.cnpm.dingdandao.com/error-provider/download/error-provider-0.0.6.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"Gagle","email":"gaglekas@gmail.com"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"directories":{},"deprecated":"deprecated","publish_time":1362874677063,"_cnpm_publish_time":1362874677063,"_hasShrinkwrap":false},"0.0.5":{"name":"error-provider","version":"0.0.5","description":"Manages errors for third-party modules","keywords":["error","errno","provider","libuv"],"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"engines":{"node":"*"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.html"}],"main":"lib/error-provider","readmeFilename":"README.md","_id":"error-provider@0.0.5","dist":{"shasum":"71941074610f4f98ac6c879c2524b374e044eb97","size":4180,"noattachment":false,"key":"/error-provider/-/error-provider-0.0.5.tgz","tarball":"http://registry.cnpm.dingdandao.com/error-provider/download/error-provider-0.0.5.tgz"},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"Gagle","email":"gaglekas@gmail.com"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"directories":{},"deprecated":"deprecated","publish_time":1362485537916,"_cnpm_publish_time":1362485537916,"_hasShrinkwrap":false},"0.0.4":{"name":"error-provider","version":"0.0.4","description":"Manages errors for third-party modules","keywords":["error","errno","provider","libuv"],"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"engines":{"node":"*"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.html"}],"main":"lib/error-provider","readmeFilename":"README.md","_id":"error-provider@0.0.4","dist":{"shasum":"8d89495aeca7436fbd33f462e6c32f886453f28c","size":4161,"noattachment":false,"key":"/error-provider/-/error-provider-0.0.4.tgz","tarball":"http://registry.cnpm.dingdandao.com/error-provider/download/error-provider-0.0.4.tgz"},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"Gagle","email":"gaglekas@gmail.com"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"directories":{},"deprecated":"deprecated","publish_time":1362124448168,"_cnpm_publish_time":1362124448168,"_hasShrinkwrap":false},"0.0.3":{"name":"error-provider","version":"0.0.3","description":"Manages errors for third-party modules","keywords":["error","errno","provider","libuv"],"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"engines":{"node":"*"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.html"}],"main":"lib/error-provider","readmeFilename":"README.md","_id":"error-provider@0.0.3","dist":{"shasum":"dbbb0e66095b38b15db6e05f3dec8e1bf52624b4","size":4115,"noattachment":false,"key":"/error-provider/-/error-provider-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/error-provider/download/error-provider-0.0.3.tgz"},"_from":".","_npmVersion":"1.2.11","_npmUser":{"name":"Gagle","email":"gaglekas@gmail.com"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"directories":{},"deprecated":"deprecated","publish_time":1361989724677,"_cnpm_publish_time":1361989724677,"_hasShrinkwrap":false},"0.0.2":{"name":"error-provider","version":"0.0.2","description":"Manages errors for third-party modules","keywords":["error","errno","provider","libuv"],"author":{"name":"Gabriel Llamas","email":"gaglekas@gmail.com"},"repository":{"type":"git","url":"git://github.com/Gagle/Node-ErrorProvider.git"},"engines":{"node":"*"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/mit-license.html"}],"main":"lib/error-provider","readmeFilename":"README.md","_id":"error-provider@0.0.2","dist":{"shasum":"91ae97ed1436abcff2fe10e83b9c36fa9268e50b","size":3898,"noattachment":false,"key":"/error-provider/-/error-provider-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/error-provider/download/error-provider-0.0.2.tgz"},"_from":".","_npmVersion":"1.2.2","_npmUser":{"name":"Gagle","email":"gaglekas@gmail.com"},"maintainers":[{"name":"gagle","email":"gabriel_llamas_llopis@yahoo.es"}],"directories":{},"deprecated":"deprecated","publish_time":1358702343455,"_cnpm_publish_time":1358702343455,"_hasShrinkwrap":false}},"readme":"error-provider\r\n==============\r\n\r\n_Node.js project_\r\n\r\n#### Manages errors for third-party modules ####\r\n\r\nVersion: 0.0.2\r\n\r\nWhen you're writing a third-party module you'll probably deal with errors. If you want to send custom errors to your users you should send a code and then in your documentation explain these codes.\r\n\r\nThis module eases the error management, you only need to give a number, a code and a description and when you need them just get and throw them.\r\n\r\nThe built-in errors are also available so if you need to manually throw a `EEXIST` you can do so.\r\n\r\nThe error description accepts variables, that is, you can create an error with a variable and when you get it you can set the variable value:\r\n\r\n```javascript\r\nep.create (1000, \"MY_CUSTOM_ERROR\", \"This is a {which} error\");\r\nconsole.log (ep.get (\"MY_CUSTOM_ERROR\", { which: \"custom\" }));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: MY_CUSTOM_ERROR]\r\n  errno: 1000,\r\n  code: \"MY_CUSTOM_ERROR\",\r\n  description: \"This is a custom error\" }\r\n*/\r\n```\r\n\r\nIf you want to add another property different from `errno`, `code` and `description` you can do it, just pass an object with the new properties (if the property value is a string it can also have variables):\r\n\r\n```javascript\r\nep.create (ep.next (), \"MY_CUSTOM_ERROR\", \"This is a {which} error\", {\r\n\tpath: \"{path}\",\r\n\tfn: function (){\r\n\t\tconsole.log (\"custom error\");\r\n\t}\r\n});\r\nvar error = ep.get (\"MY_CUSTOM_ERROR\", { which: \"custom\", path: \"some/path\" });\r\nerror.fn ();\r\nconsole.log (error);\r\n\r\n/*\r\nPrints:\r\n\r\ncustom error\r\n{ [Error: MY_CUSTOM_ERROR]\r\n  errno: 100,\r\n  code: \"MY_CUSTOM_ERROR\",\r\n  description: \"This is a custom error\",\r\n  path: \"some/path\",\r\n  fn: [Function] }\r\n*/\r\n```\r\n\r\n#### Installation ####\r\n\r\n```\r\nnpm install error-provider\r\n```\r\n\r\n#### Example ####\r\n\r\n```javascript\r\nvar ep = require (\"error-provider\");\r\n\r\nconsole.log (ep.get (ep.ENOENT));\r\n\r\nvar n = ep.next ();\r\nep.create (n, \"TEST1\", \"test 1\");\r\nconsole.log (ep.get (ep.TEST1));\r\nconsole.log (ep.get (\"TEST1\"));\r\nconsole.log (ep.get (n));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: ENOENT]\r\n  errno: 34,\r\n  code: \"ENOENT\",\r\n  description: \"no such file or directory\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n{ [Error: TEST1] errno: 100, code: \"TEST1\", description: \"test 1\" }\r\n*/\r\n```\r\n\r\n#### Methods ####\r\n\r\n- [ep.create(errno, code, description[, properties])](#create)\r\n- [ep.get(id[, vars])](#get)\r\n- [ep.next()](#next)\r\n\r\n<a name=\"create\"></a>\r\n__ep.create(errno, code, description[, properties])__  \r\nCreates an error with an id, code, description and additional properties.\r\n\r\nThe strings can contain variables that can be set later. A variable is a name encapsulated inside curly braces:\r\n\r\n```javascript\r\nep.create (ep.next (), \"TEST1\", \"Test 1\", {\r\n\tpath: \"{p}\"\r\n});\r\nconsole.log (ep.get (\"TEST1\", { p: \"some/path\" }));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: TEST1]\r\n  errno: 100,\r\n  code: \"TEST1\",\r\n  description: \"Test 1\",\r\n  path: \"some/path\" }\r\n*/\r\n```\r\n\r\n<a name=\"get\"></a>\r\n__ep.get(id[, vars])__  \r\nReturns an error. It can be a Node.js built-in error such as `ENOENT` or one that was created previously.\r\n\r\nThe `id` can be a Number, String or Object:\r\n\r\n```javascript\r\nep.create (ep.next (), \"TEST1\", \"Test 1\");\r\nconsole.log (ep.get (ep.TEST1));\r\nconsole.log (ep.get (\"TEST1\"));\r\nconsole.log (ep.get (100));\r\n```\r\n\r\nIf `vars` is provided, the variables found in the error properties that are String will be set with the given value.\r\n\r\n```javascript\r\nep.create (ep.next (), \"TEST1\", \"Test {number}\", {\r\n\tn: \"{number}\",\r\n\tp: \"{value}\"\r\n});\r\nconsole.log (ep.get (\"TEST1\", { number: 1, value: \"ok\" }));\r\n\r\n/*\r\nPrints:\r\n\r\n{ [Error: TEST1]\r\n  errno: 100,\r\n  code: \"TEST1\",\r\n  description: \"Test 1\",\r\n  n: \"1\",\r\n  p: \"ok\" }\r\n*/\r\n```\r\n\r\n<a name=\"next\"></a>\r\n__ep.next()__  \r\nReturns the next available error number and increments the counter. This number is an identifier to create errors.\r\n\r\nThe first available number starts at 100.\r\n\r\nThe following example creates three errors with identified with 100, 101 and 102.\r\n\r\n```javascript\r\nep.create (ep.next (), ...);\r\nep.create (ep.next (), ...);\r\nep.create (ep.next (), ...);\r\n```","_attachments":{},"readmeFilename":"README.md"}