{"_id":"module-error","_rev":"4-b464bac9e0bcead5af8bba8188cc4f30","name":"module-error","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"module-error","version":"1.0.0","description":"Create errors with code and cause properties","license":"MIT","author":{"name":"Vincent Weevers"},"scripts":{"test":"standard && tsc && hallmark && node test"},"devDependencies":{"@types/node":"^16.11.3","@voxpelli/tsconfig":"^3.0.0","hallmark":"^3.1.0","standard":"^16.0.4","tape":"^5.3.1","typescript":"^4.4.4"},"keywords":["cause","code","error"],"repository":{"type":"git","url":"git+https://github.com/vweevers/module-error.git"},"bugs":{"url":"https://github.com/vweevers/module-error/issues"},"homepage":"https://github.com/vweevers/module-error","engines":{"node":">=10"},"gitHead":"fae7ba26422960c9cba0ab6ebe8bd7f60d13ee3c","_id":"module-error@1.0.0","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-XhGjziMYG33U69jQ1vzts/FQCU/nB8/AZJo+f5DKh9JsyuLxqJcjvMEuW0woPNkGWP06yOR9oWkEy53kXzRP/g==","shasum":"4084a0db2a84b26ae123a35c836b24bde59de629","tarball":"https://registry.npmjs.org/module-error/-/module-error-1.0.0.tgz","fileCount":5,"unpackedSize":6394,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDcJftz65qmdotx2bUp/t5Dc/SMUq1fhmcDaZeHHWRPsAIhAPVArH0+DbWghW0lTGnNAKFf9BaypIG+TKk4e7Ncg/mE"}]},"_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"directories":{},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/module-error_1.0.0_1634909822193_0.7919414773013909"},"_hasShrinkwrap":false},"1.0.1":{"name":"module-error","version":"1.0.1","description":"Create errors with code and cause properties","license":"MIT","author":{"name":"Vincent Weevers"},"scripts":{"test":"standard && tsc && hallmark && node test","build":"tsc -d --emitDeclarationOnly --noEmit false"},"types":"./index.d.ts","devDependencies":{"@types/node":"^16.11.3","@voxpelli/tsconfig":"^3.0.0","hallmark":"^3.1.0","standard":"^16.0.4","tape":"^5.3.1","typescript":"^4.4.4"},"keywords":["cause","code","error"],"repository":{"type":"git","url":"git+https://github.com/vweevers/module-error.git"},"bugs":{"url":"https://github.com/vweevers/module-error/issues"},"homepage":"https://github.com/vweevers/module-error","engines":{"node":">=10"},"gitHead":"9cc6c8304a39c21954d2f13a530f99361b207d10","_id":"module-error@1.0.1","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-cB9FwYHnQjyeritmtnHT9RefDQtwB346haYV8L1ltkvx5hgTRNyU/PpDogwn0Enk66ZXkDU5NykVoM2WfKfLew==","shasum":"761dc56831e2fabe6d9f780bbe4980a0b4ca2331","tarball":"https://registry.npmjs.org/module-error/-/module-error-1.0.1.tgz","fileCount":6,"unpackedSize":7065,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh2zgpCRA9TVsSAnZWagAAgwsQAIkKfBE+c8/pgVIrZI3d\nqMLQSLLJvxND5acrwW1itLDMbq/lcycHJ9luRfRXn9h3TLt19YTMSeMbFt9V\nejl1HeUeoIBZpHK8hDizsex4QRQh7H+4LThuCbVv6MBatbBarp56CE6s0aq0\nGp00ujqYJHLB46zeFLREveU88allJ7RuI1kSd+sPZCVO9C+MmONDV8yNMku4\n1SyHalMv3iJZyG6fwLZdI0vhCZ5XxNQJO0sSUzgP3rngN8y8YpFog72DK/Ah\nSj+s2qHgitJH5hWPtpfmszenKr46hrueUSS7uYaH9qHAP87qJBsNKmk/lbtH\ntlfOhRHg87JQ/gCDAO2F9y78MAGduEJnl8Yjc+bdiTwkCADKlaHaZl1bO2Na\nxnuS6GHBjgbR8irigDMzogmJzGZISdZ87DPa8UbTnjokHMfmF9jRC2UUapNx\n3RvHb2r90zMI5e1Vomzy10tVIttXwEoWDPxIzznTgH/gYapuuEmBXQY2btZh\nl08+SieiKUDsX6ynQ+oHYyLL5jq/yufYGKxmKRTAuz4xWpiNJ4aENf34peNY\nChk31OdyVKVSqaIRcG8HctTTvKQAMIZr3CNd4NcqFuUYa1ft3sf9S6zdrOh1\nq15DexlUMOhPbRV7X0yOR/uterkwiH34f3IS+9DMM+jo/JNSB+iC60d23O7A\np6pu\r\n=9zHm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCbRGIVN0vwShPv5b1AOQyQgcNis61FvG7Y4GELdaVVzwIgOSC5GluVEETe995wyjdq/ga6KhnYYtVFb8tsYczDQQg="}]},"_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"directories":{},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/module-error_1.0.1_1635108562506_0.27540223262218677"},"_hasShrinkwrap":false},"1.0.2":{"name":"module-error","version":"1.0.2","description":"Create errors with code and cause properties","license":"MIT","author":{"name":"Vincent Weevers"},"scripts":{"test":"standard && tsc && hallmark && node test","build":"tsc -d --emitDeclarationOnly --noEmit false"},"types":"./index.d.ts","devDependencies":{"@types/node":"^17.0.6","@voxpelli/tsconfig":"^3.0.0","hallmark":"^4.0.0","standard":"^16.0.4","tape":"^5.3.1","typescript":"^4.4.4"},"keywords":["cause","code","error"],"repository":{"type":"git","url":"git+https://github.com/vweevers/module-error.git"},"bugs":{"url":"https://github.com/vweevers/module-error/issues"},"homepage":"https://github.com/vweevers/module-error","engines":{"node":">=10"},"gitHead":"bcbdc3614fdf1e75e94032671fad893cabf796a4","_id":"module-error@1.0.2","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA==","shasum":"8d1a48897ca883f47a45816d4fb3e3c6ba404d86","tarball":"https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz","fileCount":6,"unpackedSize":7281,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiEQ/xACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoW1w//YuVGBpfBCEmQJJEVVdcm9Vqiz1PQGrOe+TD13OKxQ2vaS//h\r\nLW1myi6SkkweWarnN7ZiVHUF8KpS285KwiazEcEsm4Yv75xP4jbTurmPSfx0\r\nXX9GvseZsFE92EbMdgAwF77WrAPEPbX1STUWBFPRaNkFlEH0bjwJXC9xqW08\r\n2FTf9B/nYp3NSYTgMW3QYqoRCVJjKDK4t4kkU0iIb036gP00TamOTHeMplP2\r\njKQDAwDlmXRPNzWGXCjkadK+rcBPOogn7MauXtlpH5i9VGIogsFYq1+z+ySI\r\nD13SWWKyrwJLpPWhYZ3NeXMehAMsYcakSppCJO4wjPWRCY6PKSnoFHKXV823\r\nb3rHnV5VTrDucPsVaCSmphb+w17iOZxR50Sgd0PO+GA+T9tL3q69TU7q+ahR\r\nX0hTQN5w4q4G6k1JuGaEjefGKu4D9vwpitjsejA2CvzToLTeu3FQeTXy47C1\r\n+8gY2mFELMkqxu2oPAAj3KnzywE4LNBp33TP135dFeO1IdMDepNk15vYThPB\r\ndu+vPpB95GclcclBPgPra29H9nCti0QlAnmKJ0h8BnZZJdOUyDtEroFEUMVb\r\nErWtwDVHftAvmQTz2QJAuPCaXexAZOG3oB/ez/5JGAGcDY/Qd/wCJ2VOseXS\r\nTzWbYG3NitVJQX1+SHE7Tj6m//pvpuhUNdU=\r\n=X8kw\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCaltibYeodcZ5ZV6I5/8D2SmZuwLT6kHjYxy8uceFyXAIhAM+R4AoJYoi0frA8Sw4TXz7Inf2KQGjNmQ3qo7VdktZ+"}]},"_npmUser":{"name":"vweevers","email":"dev@vincentweevers.nl"},"directories":{},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/module-error_1.0.2_1645285361491_0.370455362840016"},"_hasShrinkwrap":false}},"time":{"created":"2021-10-22T13:37:02.192Z","1.0.0":"2021-10-22T13:37:02.421Z","modified":"2022-05-09T15:56:13.849Z","1.0.1":"2021-10-24T20:49:22.652Z","1.0.2":"2022-02-19T15:42:41.644Z"},"maintainers":[{"name":"vweevers","email":"dev@vincentweevers.nl"}],"description":"Create errors with code and cause properties","homepage":"https://github.com/vweevers/module-error","keywords":["cause","code","error"],"repository":{"type":"git","url":"git+https://github.com/vweevers/module-error.git"},"author":{"name":"Vincent Weevers"},"bugs":{"url":"https://github.com/vweevers/module-error/issues"},"license":"MIT","readme":"# module-error\n\n**Create errors with `code` and `cause` properties. Simple and extensible.**\n\n[![npm status](http://img.shields.io/npm/v/module-error.svg)](https://www.npmjs.org/package/module-error)\n[![node](https://img.shields.io/node/v/module-error.svg)](https://www.npmjs.org/package/module-error)\n[![Test](https://img.shields.io/github/workflow/status/vweevers/module-error/Test?label=test)](https://github.com/vweevers/module-error/actions/workflows/test.yml)\n[![Standard](https://img.shields.io/badge/standard-informational?logo=javascript&logoColor=fff)](https://standardjs.com)\n[![Common Changelog](https://common-changelog.org/badge.svg)](https://common-changelog.org)\n\n## Usage\n\nWorks like a regular `Error` constructor but adds an options argument (as [`proposal-error-cause`](https://github.com/tc39/proposal-error-cause) does).\n\n```js\nconst ModuleError = require('module-error')\n\nthrow new ModuleError('Message goes here', {\n  code: 'EXAMPLE_NOT_FOUND'\n})\n```\n\nThe primary purpose of `ModuleError` is to define a `code` property on the error object following Node.js conventions. It should be set to an uppercase string that uniquely identifies a situation, prefixed with the name of your module (or a collection of modules) to prevent conflicts.\n\nThe output looks like this in Node.js (some stack frames omitted for brevity):\n\n```\nModuleError: Message goes here\n    at Object.<anonymous> (/home/app/example.js:5:7)\n    at node:internal/main/run_main_module:17:47 {\n  code: 'EXAMPLE_NOT_FOUND'\n}\n```\n\nThe benefit of error codes is that messages can be changed without a semver-major release because your [semver](https://semver.org) contract will be on the codes. Codes can be reused across related modules while allowing individual modules to customize messages. I also prefer it over `instanceof MyError` logic because codes work cross-realm and when a tree of `node_modules` contains multiple versions of a module.\n\nTo wrap another error:\n\n```js\ntry {\n  JSON.parse(await fs.readFile('state.json'))\n} catch (err) {\n  throw new ModuleError('Could not load state', {\n    code: 'EXAMPLE_INVALID_STATE',\n    cause: err\n  })\n}\n```\n\nIf for convenience you want to create subclasses with prepared codes:\n\n```js\nclass NotFoundError extends ModuleError {\n  constructor(message, options) {\n    super(message, { ...options, code: 'EXAMPLE_NOT_FOUND' })\n  }\n}\n```\n\nThen you can do:\n\n```js\nthrow new NotFoundError('Message goes here')\n```\n\nUnder Node.js the stack trace will be adjusted accordingly, to skip the frame containing your error constructor.\n\n## API\n\n### `ModuleError(message, [options])`\n\nConstructor to create an error with the provided `message` string. Options:\n\n- `code` (string): if provided, define a `code` property with this value.\n- `cause` (Error): if provided, define a `cause` property with this value. Unlike the spec of [`proposal-error-cause`](https://github.com/tc39/proposal-error-cause) the property is enumerable so that Node.js (v16 at the time of writing) will print it. Firefox prints it regardless, Chromium doesn't yet.\n- `expected`: if truthy, define a `expected` property with value `true`. This is useful for command line interfaces to differentiate unexpected errors from e.g. invalid user input. A pattern I like to follow is to print only an error message if `err.expected` is true and no `--verbose` flag was provided. Otherwise print the full stack.\n- `transient`: if truthy, define a `transient` property with value `true`. This communicates to users that the operation that caused the error may be retried. See also [`transient-error`](https://github.com/vweevers/transient-error) to mark existing errors as transient.\n\n## Install\n\nWith [npm](https://npmjs.org) do:\n\n```\nnpm install module-error\n```\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md"}