{"name":"yerror","version":"1.0.1","description":"It helps to know why you got an error.","main":"src/index.js","scripts":{"test":"node_modules/mocha/bin/mocha tests/*.mocha.js","coveralls":"./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha --report lcovonly -- tests/*.mocha.js -R spec -t 5000 && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage","cover":"./node_modules/istanbul/lib/cli.js cover --report html ./node_modules/mocha/bin/_mocha -- tests/*.mocha.js -R spec -t 5000"},"engines":{"node":">=0.10.0"},"repository":{"type":"git","url":"git://github.com/SimpliField/yerror.git"},"keywords":["error","why","better"],"author":{"name":"Nicolas Froidure","url":"Simplifield"},"license":"BSD-2-Clause","bugs":{"url":"https://github.com/SimpliField/yerror/issues"},"devDependencies":{"mocha":"~2.2.5","mocha-lcov-reporter":"0.0.2","coveralls":"~2.11.2","istanbul":"~0.3.17"},"dependencies":{},"gitHead":"9666d1a230e4c4394bf64329c9787f3fbabb5b95","homepage":"https://github.com/SimpliField/yerror","_id":"yerror@1.0.1","_shasum":"015455aba0b399d617d509231c261fb7c45985a2","_from":".","_npmVersion":"2.5.1","_nodeVersion":"0.12.0","_npmUser":{"name":"nfroidure","email":"nfroidure@elitwork.com"},"maintainers":[{"name":"nfroidure","email":"nfroidure@elitwork.com"},{"name":"gplancke","email":"georges.plancke@gmail.com"}],"dist":{"shasum":"015455aba0b399d617d509231c261fb7c45985a2","tarball":"http://registry-npm.ywwl.com/yerror/download/yerror-1.0.1.tgz","integrity":"sha512-YfFzIOI8tBUl1pcf2hWeC6ogE4LO0+j0Ax1rpxGunvTzTs/aSHsMUUObBCMTLvpzqlMfxjgmjy0up50DcpOTBA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGtYaqdA5fQz3kYBkDFo0W2mywWxFKcGgZdzjQ/uSH26AiEAwuRgV+qvViUrPSYhODM3MQaRzObYQxkHZjwbbVlObfw="}],"size":3790,"noattachment":false,"key":"/yerror/-/yerror-1.0.1.tgz"},"directories":{},"readme":"[//]: # ( )\n[//]: # (This file is automatically generated by a `metapak`)\n[//]: # (module. Do not change it  except between the)\n[//]: # (`content:start/end` flags, your changes would)\n[//]: # (be overridden.)\n[//]: # ( )\n# yerror\n> It helps to know why you got an error.\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/yerror/blob/main/LICENSE)\n[![Coverage Status](https://coveralls.io/repos/github/git://github.com/nfroidure/yerror.git/badge.svg?branch=main)](https://coveralls.io/github/git://github.com/nfroidure/yerror.git?branch=main)\n\n\n[//]: # (::contents:start)\n\n## Usage\n\nFirst, require me where you could throw errors:\n\n```js\nimport YError from 'yerror';\n```\n\nThen, emit errors with a bonus: parameters!\n\n```js\nfunction doSomething(pay, action) {\n  if(parseInt(pay, 10) !== pay) {\n    throw new YError('E_BAD_PAY', pay, action);\n  }\n}\n\ndoSomething('nuts', 'code');\n\n\n// YError: E_BAD_PAY (nuts, code)\n//   at doSomething (/home/nfroidure/nfroidure/yerror/test.js:5:11)\n//   at Object.<anonymous> (/home/nfroidure/nfroidure/yerror/test.js:9:1)\n//   (...)\n```\n\nYou don't have to use constant like error messages, we use this convention\nmainly for i18n reasons.\n\nAlso, you could want to wrap errors and keep a valuable stack trace:\n\n```js\nfunction doSomethingAsync(pay, action) {\n  return  new Promise(function(resolve, reject) {\n    try {\n      doSomething(pay, action);\n      resolve();\n    } catch(err) {\n      reject(YError.bump(err));\n    }\n  });\n}\n\ndoSomethingAsync('nuts', 'code')\n  .catch(function(err) {\n    console.log(err.stack);\n  });\n\n// YError: E_BAD_PAY (nuts, code)\n//    at doSomething (/home/nfroidure/nfroidure/yerror/test.js:5:11)\n//    (...)\n// YError: E_BAD_TRANSACTION (pay)\n//    at Function.YError.wrap (/home/nfroidure/nfroidure/yerror/src/index.js:41:12)\n//    at /home/nfroidure/nfroidure/yerror/test.js:16:21\n//    at doSomethingAsync (/home/nfroidure/nfroidure/yerror/test.js:11:11)\n//    (...)\n```\n\n\n[//]: # (::contents:end)\n\n# API\n## Classes\n\n<dl>\n<dt><a href=\"#YError\">YError</a> ⇐ <code>Error</code></dt>\n<dd><p>A YError class able to contain some params and\n print better stack traces</p>\n</dd>\n</dl>\n\n## Functions\n\n<dl>\n<dt><a href=\"#printStackTrace\">printStackTrace(err)</a> ⇒ <code>string</code></dt>\n<dd><p>Allow to print a stack from anything (especially catched\n errors that may or may not contain errors 🤷).</p>\n</dd>\n</dl>\n\n<a name=\"YError\"></a>\n\n## YError ⇐ <code>Error</code>\nA YError class able to contain some params and\n print better stack traces\n\n**Kind**: global class  \n**Extends**: <code>Error</code>  \n\n* [YError](#YError) ⇐ <code>Error</code>\n    * [.wrap(err, [errorCode], [...params])](#YError.wrap) ⇒ [<code>YError</code>](#YError)\n    * [.cast(err, [errorCode], [...params])](#YError.cast) ⇒ [<code>YError</code>](#YError)\n    * [.bump(err, [errorCode], [...params])](#YError.bump) ⇒ [<code>YError</code>](#YError)\n\n<a name=\"YError.wrap\"></a>\n\n### YError.wrap(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)\nWraps any error and output a YError with an error\n code and some params as debug values.\n\n**Kind**: static method of [<code>YError</code>](#YError)  \n**Returns**: [<code>YError</code>](#YError) - The wrapped error  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| err | <code>Error</code> |  | The error to wrap |\n| [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |\n| [...params] | <code>YErrorParams</code> |  | Some additional debugging values |\n\n<a name=\"YError.cast\"></a>\n\n### YError.cast(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)\nReturn a YError as is or wraps any other error and output\n a YError with a code and some params as debug values.\n\n**Kind**: static method of [<code>YError</code>](#YError)  \n**Returns**: [<code>YError</code>](#YError) - The wrapped error  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| err | <code>Error</code> |  | The error to cast |\n| [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |\n| [...params] | <code>YErrorParams</code> |  | Some additional debugging values |\n\n<a name=\"YError.bump\"></a>\n\n### YError.bump(err, [errorCode], [...params]) ⇒ [<code>YError</code>](#YError)\nSame than `YError.wrap()` but preserves the code\n and the debug values of the error if it is\n already an instance of the YError constructor.\n\n**Kind**: static method of [<code>YError</code>](#YError)  \n**Returns**: [<code>YError</code>](#YError) - The wrapped error  \n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| err | <code>Error</code> |  | The error to bump |\n| [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |\n| [...params] | <code>YErrorParams</code> |  | Some additional debugging values |\n\n<a name=\"printStackTrace\"></a>\n\n## printStackTrace(err) ⇒ <code>string</code>\nAllow to print a stack from anything (especially catched\n errors that may or may not contain errors 🤷).\n\n**Kind**: global function  \n**Returns**: <code>string</code> - The stack trace if any  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| err | <code>Error</code> | The error to print |\n\n\n# Authors\n- [Nicolas Froidure (formerly at SimpliField)](http://insertafter.com/en/index.html)\n\n# License\n[MIT](https://github.com/nfroidure/yerror/blob/main/LICENSE)\n","publish_time":1435657305448,"_cnpm_publish_time":1435657305448,"dist-tags":{"latest":"11.0.0"}}