{"id":21414877,"url":"https://github.com/magic/error","last_synced_at":"2025-10-19T21:56:27.272Z","repository":{"id":54290348,"uuid":"233972184","full_name":"magic/error","owner":"magic","description":"create errors with custom name and message","archived":false,"fork":false,"pushed_at":"2023-02-16T07:37:59.000Z","size":636,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-08T05:46:04.557Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-15T01:34:57.000Z","updated_at":"2021-12-26T16:47:20.000Z","dependencies_parsed_at":"2024-06-21T05:47:46.899Z","dependency_job_id":"47e1bc4c-c4b9-496b-b3dd-c3c206fd5ef5","html_url":"https://github.com/magic/error","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ferror","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ferror/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ferror/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magic%2Ferror/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magic","download_url":"https://codeload.github.com/magic/error/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243911273,"owners_count":20367651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T18:34:23.364Z","updated_at":"2025-10-19T21:56:27.264Z","avatar_url":"https://github.com/magic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @magic/error\n\nthrow errors with custom code/name.\n\n[html-docs](https://magic.github.io/error)\n\n[![NPM version][npm-image]][npm-url]\n[![Linux Build Status][travis-image]][travis-url]\n[![Windows Build Status][appveyor-image]][appveyor-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Known Vulnerabilities][snyk-image]][snyk-url]\n\n[npm-image]: https://img.shields.io/npm/v/@magic/error.svg\n[npm-url]: https://www.npmjs.com/package/@magic/error\n[travis-image]: https://img.shields.io/travis/com/magic/error/master\n[travis-url]: https://travis-ci.com/magic/error\n[appveyor-image]: https://img.shields.io/appveyor/ci/magic/error/master.svg\n[appveyor-url]: https://ci.appveyor.com/project/magic/error/branch/master\n[coveralls-image]: https://coveralls.io/repos/github/magic/error/badge.svg\n[coveralls-url]: https://coveralls.io/github/magic/error\n[snyk-image]: https://snyk.io/test/github/magic/error/badge.svg\n[snyk-url]: https://snyk.io/test/github/magic/error\n\n### installation:\n\n```javascript\nnpm install @magic/error\n```\n\n### usage:\n\n```javascript\nimport error from '@magic/error'\n\nerr = error('message', 'name')\n// Error { message: 'message', name: 'name', code: 'E_NAME', type: 'E', msg: 'message' }\n\nerr = error('message')\n// Error { message: 'message', name: 'Unknown', code: 'E_UNKNOWN', type: 'E', msg: 'message' }\n\nerr = error(new Error('message'))\n// Error { message: 'message', name: 'Error', code: 'E_UNKNOWN', type: 'E', msg: 'message' }\n\nerr = error('message', 'name with spaces')\n// Error {\n//  message: 'message',\n//  name: 'name with spaces',\n//  code: 'E_NAME_WITH_SPACES',\n//  type: 'E',\n//  msg: 'message',\n// }\n\nerr = error(['message', 'name', 'T'])\n// Error { message: 'message', name: 'name', code: 'T_NAME', type: T, msg: 'message' }\n\nerr = error(['message'], 'name', 'T')\n// Error { message: 'message', name: 'name', code: 'T_NAME', type: T, msg: 'message' }\n\nerr = error(['message', 'name1'], 'name2', 'T')\n// Error { message: 'message', name: 'name1', code: 'T_NAME1', type: T, msg: 'message' }\n```\n\n#### error types\n\nerrors can have types\n\n```javascript\n// E is the default type\nerr = error('message', 'name')\n// Error { message: 'message', name: 'name', code: 'E_NAME', type: 'E', msg: 'message' }\n\n// warnings:\nerr = error('message', 'name', 'W')\n// Error { message: 'message', name: 'name', code: 'W_NAME', type: 'W', msg: 'message' }\n\n// debug:\nerr = error('message', 'name', 'D')\n// Error { message: 'message', name: 'name', code: 'D_NAME', type: 'D', msg: 'message' }\n```\n\n##### changelog\n\n##### 0.0.1\n\nfirst commit\n\n#### 0.0.2\n\n- errors can be passed as first argument\n- error.name is unchanged, error.code gets transformed to start with E\\_ and be uppercased.\n- error.code for passed in errors is E_UNKNOWN.\n\n#### 0.0.3\n\n- error type (third fn argument) can now be set, default is E to keep output the same.\n- error name (second fn argument) can now be a string with spaces.\n  e.code is e.type + e.name, but UPPER_SNAKE_CASED.\n- error stack cleanup improved.\n\n#### 0.0.4\n\n- err.msg is no === err.message\n- first argument can be an array of [message, name, type]\n\n#### 0.0.5\n\n- fix replacement of : in error name and error message to only replace the ones we want to replace\n\n#### 0.0.6\n\nbump required node version to 14.2.0\n\n#### 0.0.7\n\nupdate depdendencies\n\n#### 0.0.8\n\n- bump required node version to 14.15.4\n- update dependencies\n\n##### 0.0.9\n\nupdate dependencies\n\n##### 0.0.10\n\nupdate @magic/types to avoid circular dependency\n\n##### 0.0.11\n\n- use @magic/types internally\n- update dependencies\n\n##### 0.0.12\n\nupdate dependencies\n\n##### 0.0.13\n\nupdate dependencies\n\n##### 0.0.14\n\nupdate dependencies\n\n##### 0.0.15\n\nupdate dependencies\n\n##### 0.0.16\n\nupdate dependencies\n\n##### 0.0.17\n\nupdate dependencies\n\n##### 0.0.18\n\n- add typescript types\n- update dependencies\n\n##### 0.0.19\n\n- export types from types dir...\n\n##### 0.0.20\n\n- pkg: add types dir to files array\n\n##### 0.0.21 - unreleased\n\n...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagic%2Ferror","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagic%2Ferror","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagic%2Ferror/lists"}