{"metapak":{"configs":["main","readme","tsesm","eslint","jest","codeclimate","ghactions","jsdocs"],"data":{"files":"'src/**/*.ts'","testsFiles":"'src/**/*.test.ts'","distFiles":"'dist/**/*.js'","ignore":["dist"],"bundleFiles":["dist","src"]}},"name":"yerror","version":"11.0.0","description":"It helps to know why you got an error.","scripts":{"build":"rimraf 'dist' && tsc --outDir dist","changelog":"conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md","cli":"env NODE_ENV=${NODE_ENV:-cli}","commitlint":"commitlint","cover":"node --run jest -- --coverage","doc":"echo \"# API\" > API.md; jsdoc2md 'dist/**/*.js' >> API.md && git add API.md","format":"node --run prettier","jest":"NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest","lint":"eslint 'src/**/*.ts'","metapak":"metapak","precommit":"node --run test && node --run lint && node --run build && node --run doc && node --run metapak -- -s","prettier":"prettier --write 'src/**/*.ts'","preversion":"node --run test && node --run lint && node --run build && node --run doc && node --run metapak -- -s","rebuild":"swc ./src -s -d dist -C jsc.target=es2022","test":"node --run jest","version":"node --run changelog"},"engines":{"node":">=24.14.0"},"repository":{"type":"git","url":"git://github.com/nfroidure/yerror.git"},"keywords":["error","why","better"],"author":{"name":"Nicolas Froidure","email":"nicolas.froidure@insertafter.com","url":"formerly at SimpliField"},"license":"MIT","bugs":{"url":"https://github.com/nfroidure/yerror/issues"},"devDependencies":{"@commitlint/cli":"^20.5.0","@commitlint/config-conventional":"^20.5.0","@eslint/js":"^10.0.1","@swc/cli":"^0.8.0","@swc/core":"^1.15.21","@swc/jest":"^0.2.39","conventional-changelog":"^7.2.0","eslint":"^10.1.0","eslint-config-prettier":"^10.1.8","eslint-plugin-jest":"^29.15.1","eslint-plugin-prettier":"^5.5.5","jest":"^30.3.0","jsdoc-to-markdown":"^9.1.3","metapak":"^7.0.0","metapak-nfroidure":"22.0.2","prettier":"^3.8.1","rimraf":"^6.1.3","typescript":"^6.0.2","typescript-eslint":"^8.57.2"},"contributors":[],"prettier":{"semi":true,"printWidth":80,"singleQuote":true,"trailingComma":"all","proseWrap":"always"},"funding":{"type":"individual","url":"https://github.com/sponsors/nfroidure"},"overrides":{"typescript-eslint":{"typescript":"^6"},"@typescript-eslint/eslint-plugin":{"typescript":"^6"},"@typescript-eslint/parser":{"typescript":"^6"}},"type":"module","main":"dist/index.js","types":"dist/index.d.ts","jest":{"coverageReporters":["lcov"],"testPathIgnorePatterns":["/node_modules/"],"roots":["<rootDir>/src"],"transform":{"^.+\\.tsx?$":["@swc/jest",{}]},"testEnvironment":"node","moduleNameMapper":{"(.+)\\.js":"$1"},"extensionsToTreatAsEsm":[".ts"]},"gitHead":"d49e82b713babd41c32a23b914e9d120321bd4f4","_id":"yerror@11.0.0","homepage":"https://github.com/nfroidure/yerror#readme","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-ZarH0yAHBjfiRJMC2eL8Fhv/l5GqnS2c1wo5V6vH7k4ehfHcKd6R1ahcyBZYORMH1cqPmOT1dANkoRjR2/pzrw==","shasum":"234a4d93c0dc7f47ccdede3cc9509b0d43bee885","tarball":"http://registry-npm.ywwl.com/yerror/download/yerror-11.0.0.tgz","fileCount":12,"unpackedSize":67104,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDc96QsVJESBs5XisrzXuQ0SLIg1Tb1r4yY9/hhMHDDygIgDIOOsoGVGq0r8HHk+jvI+GZYVqbZ5Su/kFDmX+ZJ9YE="}],"size":13224,"noattachment":false,"key":"/yerror/-/yerror-11.0.0.tgz"},"_npmUser":{"name":"nfroidure","email":"nicolas.froidure@insertafter.com"},"directories":{},"maintainers":[{"name":"xavhan","email":"xavier.haniquaut@decathlon.com"},{"name":"nfroidure","email":"nicolas.froidure@insertafter.com"},{"name":"gplancke","email":"georges.plancke@simplifield.com"},{"name":"arnaudspanneut","email":"arnaudspanneut@gmail.com"},{"name":"sebastienelet","email":"sebastien@elet.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/yerror_11.0.0_1775551288389_0.6795246072472325"},"_hasShrinkwrap":false,"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\n\n[//]: # (::contents:start)\n\nA robust Error subclass with error codes, typed debug values, and recursive\nstack traces using native Error.cause.\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// 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').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// Caused by: 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## Global Error Registry\n\nYou can now get full autocompletion and type-safety for your error codes and\ntheir debug data.\n\n```ts\nimport { YError } from 'yerror';\n\ndeclare module 'yerror' {\n  interface YErrorRegistry {\n    E_USER_NOT_FOUND: [userId: string];\n  }\n}\n\n// TypeScript will now enforce the correct arguments:\nthrow new YError('E_USER_NOT_FOUND', ['123']);\n\n// Users of you own code will then be able to cast errors\ntry {\n  getUser('123');\n} catch (err) {\n  if (hasYErrorCode(err, 'E_USER_NOT_FOUND')) {\n    console.log(err.debug[0]);\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 debug 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 caught\n errors that may or may not contain errors 🤷).</p>\n</dd>\n<dt><a href=\"#hasYErrorCode\">hasYErrorCode(err, code)</a> ⇒ <code>boolean</code></dt>\n<dd><p>Allow to check a YError code and cast the error.</p>\n</dd>\n<dt><a href=\"#pickYErrorWithCode\">pickYErrorWithCode(err, code)</a> ⇒ <code>boolean</code></dt>\n<dd><p>Allow to check all errors for a YError code and return the casted the error.</p>\n</dd>\n</dl>\n\n<a name=\"YError\"></a>\n\n## YError ⇐ <code>Error</code>\nA YError class able to contain some debug and\n print better stack traces\n\n**Kind**: global class  \n**Extends**: <code>Error</code>  \n\n* [YError](#YError) ⇐ <code>Error</code>\n    * [new YError([errorCode], [debug], options)](#new_YError_new)\n    * [.wrap(err, [errorCode], [debug])](#YError.wrap) ⇒ [<code>YError</code>](#YError)\n    * [.cast(err, [errorCode], [debug])](#YError.cast) ⇒ [<code>YError</code>](#YError)\n    * [.bump(err, [errorCode], [debug])](#YError.bump) ⇒ [<code>YError</code>](#YError)\n\n<a name=\"new_YError_new\"></a>\n\n### new YError([errorCode], [debug], options)\nCreates a new YError with an error code\n and some debug as debug values.\n\n\n| Param | Type | Default | Description |\n| --- | --- | --- | --- |\n| [errorCode] | <code>string</code> | <code>&quot;&#x27;E_UNEXPECTED&#x27;&quot;</code> | The error code corresponding to the actual error |\n| [debug] | <code>any</code> |  | Some additional debugging values The error options |\n| options | <code>Object</code> |  | The error options |\n\n<a name=\"YError.wrap\"></a>\n\n### YError.wrap(err, [errorCode], [debug]) ⇒ [<code>YError</code>](#YError)\nWraps any error and output a YError with an error\n code and some debug 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| [debug] | <code>any</code> |  | Some additional debugging values |\n\n<a name=\"YError.cast\"></a>\n\n### YError.cast(err, [errorCode], [debug]) ⇒ [<code>YError</code>](#YError)\nReturn a YError as is or wraps any other error and output\n a YError with a code and some debug 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| [debug] | <code>any</code> |  | Some additional debugging values |\n\n<a name=\"YError.bump\"></a>\n\n### YError.bump(err, [errorCode], [debug]) ⇒ [<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| [debug] | <code>any</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 caught\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<a name=\"hasYErrorCode\"></a>\n\n## hasYErrorCode(err, code) ⇒ <code>boolean</code>\nAllow to check a YError code and cast the error.\n\n**Kind**: global function  \n**Returns**: <code>boolean</code> - The result  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| err | <code>Error</code> | The error to cast |\n| code | <code>Error</code> | The code to check |\n\n<a name=\"pickYErrorWithCode\"></a>\n\n## pickYErrorWithCode(err, code) ⇒ <code>boolean</code>\nAllow to check all errors for a YError code and return the casted the error.\n\n**Kind**: global function  \n**Returns**: <code>boolean</code> - The result  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| err | <code>Error</code> | The error to cast |\n| code | <code>Error</code> | The code to check |\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":1775551288536,"_cnpm_publish_time":1775551288536,"dist-tags":{"latest":"11.0.0"}}