{"name":"yerror","version":"9.0.0","keywords":["error","why","better"],"author":{"url":"formerly at SimpliField","name":"Nicolas Froidure","email":"nicolas.froidure@insertafter.com"},"license":"MIT","_id":"yerror@9.0.0","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"}],"contributors":[],"homepage":"https://github.com/nfroidure/yerror#readme","bugs":{"url":"https://github.com/nfroidure/yerror/issues"},"nyc":{"exclude":["src/*.mocha.js"]},"dist":{"shasum":"2f8b11c3ca8e149961357dcc6afc49ca64a22bf9","tarball":"http://registry-npm.ywwl.com/yerror/download/yerror-9.0.0.tgz","fileCount":12,"integrity":"sha512-uTC7sL7ly+mjwJyY9JWmYyMt/y8KyYXMZ9mepO+TtXECp4UKmTGP5stYxNdxhk9GA02uZPF966969egMqaQZmw==","signatures":[{"sig":"MEYCIQCAv+EMT7MBEWiS50BUbC6baAv8RHt7Neie5Lit3v/GYAIhAOysB0SQBD1iB20Oztl/y4ZRboCvO9OrtDurtqH6Zr6b","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":52186,"size":10283,"noattachment":false,"key":"/yerror/-/yerror-9.0.0.tgz"},"jest":{"roots":["<rootDir>/src"],"transform":{"^.+\\.tsx?$":["@swc/jest",{}]},"testEnvironment":"node","moduleNameMapper":{"(.+)\\.js":"$1"},"coverageReporters":["lcov"],"extensionsToTreatAsEsm":[".ts"],"testPathIgnorePatterns":["/node_modules/"]},"main":"dist/index.js","type":"module","babel":{"env":{"cjs":{"presets":[["@babel/env",{"modules":"commonjs","targets":{"node":"10"}}]],"comments":true},"mjs":{"presets":[["@babel/env",{"modules":false,"targets":{"node":"12"}}]],"comments":false}},"plugins":[["@babel/plugin-proposal-object-rest-spread"],["@babel/plugin-transform-classes",{}],["babel-plugin-transform-builtin-extend",{"globals":["Error","Array"]}]],"presets":[["@babel/env",{"targets":{"node":"12.19.0"}}]],"sourceMaps":true},"types":"dist/index.d.ts","config":{},"engines":{"node":">=24.14.0"},"funding":{"url":"https://github.com/sponsors/nfroidure","type":"individual"},"gitHead":"32eb433ae24da53883fdb49ad53459e2703f4fb6","metapak":{"data":{"files":"'src/**/*.ts'","ignore":["dist"],"distFiles":"'dist/**/*.js'","testsFiles":"'src/**/*.test.ts'","bundleFiles":["dist","src"]},"configs":["main","readme","eslint","tsesm","jest","codeclimate","ghactions","jsdocs"]},"scripts":{"cli":"env NODE_ENV=${NODE_ENV:-cli}","doc":"echo \"# API\" > API.md; jsdoc2md 'dist/**/*.js' >> API.md && git add API.md","jest":"NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest","lint":"eslint 'src/**/*.ts'","test":"node --run jest","build":"rimraf 'dist' && tsc --outDir dist","cover":"node --run jest -- --coverage","format":"node --run prettier","metapak":"metapak","rebuild":"swc ./src -s -d dist -C jsc.target=es2022","version":"node --run changelog","prettier":"prettier --write 'src/**/*.ts'","changelog":"conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md","precommit":"node --run test && node --run lint && node --run metapak -- -s && node --run build && node --run doc","commitlint":"commitlint","preversion":"node --run test && node --run lint && node --run build && node --run metapak -- -s && node --run doc"},"_npmUser":{"name":"nfroidure","email":"nicolas.froidure@insertafter.com"},"prettier":{"semi":true,"proseWrap":"always","printWidth":80,"singleQuote":true,"trailingComma":"all"},"overrides":{"typescript-eslint":{"typescript":"^6"},"@typescript-eslint/parser":{"typescript":"^6"},"@typescript-eslint/eslint-plugin":{"typescript":"^6"}},"repository":{"url":"git://github.com/nfroidure/yerror.git","type":"git"},"_npmVersion":"11.9.0","description":"It helps to know why you got an error.","directories":{},"_nodeVersion":"24.14.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^30.3.0","eslint":"^10.1.0","rimraf":"^6.1.3","metapak":"^6.0.4","@swc/cli":"^0.8.0","prettier":"^3.8.1","@swc/core":"^1.15.21","@swc/jest":"^0.2.39","@eslint/js":"^10.0.1","typescript":"^6.0.2","@commitlint/cli":"^20.5.0","jsdoc-to-markdown":"^9.1.3","metapak-nfroidure":"21.1.1","typescript-eslint":"^8.57.2","eslint-plugin-jest":"^29.15.1","conventional-changelog":"^7.2.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.5","@commitlint/config-conventional":"^20.5.0"},"_npmOperationalInternal":{"tmp":"tmp/yerror_9.0.0_1774454297054_0.07812978368158752","host":"s3://npm-registry-packages-npm-production"},"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":1774454297277,"_cnpm_publish_time":1774454297277,"dist-tags":{"latest":"11.0.0"}}