{"id":23137735,"url":"https://github.com/njakob/bugsy","last_synced_at":"2025-08-17T11:32:11.781Z","repository":{"id":57146537,"uuid":"66153679","full_name":"njakob/bugsy","owner":"njakob","description":"Helper to deal with errors lifecycle in javascript","archived":false,"fork":false,"pushed_at":"2019-12-29T16:28:26.000Z","size":141,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-14T23:54:11.605Z","etag":null,"topics":["browser","errors","flowtype","helper","javascript","library","nodejs","npm","syslog","universal"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/njakob.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}},"created_at":"2016-08-20T15:26:35.000Z","updated_at":"2021-06-21T23:11:23.000Z","dependencies_parsed_at":"2022-09-06T14:52:07.232Z","dependency_job_id":null,"html_url":"https://github.com/njakob/bugsy","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/njakob/bugsy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njakob%2Fbugsy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njakob%2Fbugsy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njakob%2Fbugsy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njakob%2Fbugsy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/njakob","download_url":"https://codeload.github.com/njakob/bugsy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/njakob%2Fbugsy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270840633,"owners_count":24654994,"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","status":"online","status_checked_at":"2025-08-17T02:00:09.016Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["browser","errors","flowtype","helper","javascript","library","nodejs","npm","syslog","universal"],"created_at":"2024-12-17T13:08:47.951Z","updated_at":"2025-08-17T11:32:11.512Z","avatar_url":"https://github.com/njakob.png","language":"TypeScript","readme":"# bugsy\n\nThis library is meant to help to deal with errors lifecycle in JavaScript.\n\nError handling is a very common problem in every product. However, the language does not provide enough utils to deal with error management.\n\nThe work done in this library is inspired by personal experience while implementing more complex JavaScript projects and some other libraries such as [verror](https://github.com/joyent/node-verror).\n\n[![build status](https://img.shields.io/travis/njakob/bugsy/master.svg?style=flat-square)](https://travis-ci.org/njakob/bugsy)\n[![npm version](https://img.shields.io/npm/v/bugsy.svg?style=flat-square)](https://www.npmjs.com/package/bugsy)\n\n\n## Key Aspects\n\n* __Universal module__: This library can be used both in Node.js and in browsers.\n* __Type first__: Besides having a lot of runtime checks, the library is build to be used with type-safe extensions such as Typescript. The NPM package contains directly the Typescript definitions based on the sources.\n* __Cause chain__: While handling errors, even they might be expected, it is not always possible to recover into a proper state. In such cases, errors should be rethrown and the caller can try to handle the situation. In such cases, it might be useful to gather some metadata and keep track of previous errors.\n* __Severity__: When errors should be logged into third-party systems, not all errors have the same [severity](https://en.wikipedia.org/wiki/Syslog#Severity_level). This allows being informed only when the system is about to crash rather than on every simple network error that might occur.\n\n## Installation\n\n```sh\n$ npm install bugsy\n```\n\n## Usage\n\n\u003c!-- eslint-disable no-console --\u003e\n\u003c!-- eslint-disable no-constant-condition --\u003e\n\n```js\nimport * as bugsy from 'bugsy';\n\nconst RAN_AWAY = 'RanAwayError';\nconst THROW_MISSED = 'ThrowMissedError';\nconst CAPTURE = 'CaptureError';\n\nfunction capture(name) {\n  const r = Math.random();\n  if (r \u003c 0.3) {\n    throw new bugsy.Bugsy({\n      name: THROW_MISSED,\n      message: 'Throw totally missed',\n    });\n  }\n  if (r \u003c 0.6) {\n    throw new bugsy.Bugsy({\n      name: RAN_AWAY,\n      message: `${name} ran away, again`,\n      metadata: {\n        direction: 'north',\n      },\n    });\n  }\n  throw new Error();\n}\n\nfunction handler(func) {\n  try {\n    func();\n  } catch (error) {\n    console.error(bugsy.getFullStack(error));\n  }\n}\n\nhandler(() =\u003e {\n  while (true) {\n    try {\n      capture('Abra');\n    } catch (error) {\n      switch (true) {\n        // Expected error\n        case error.name === THROW_MISSED: {\n          console.log('I can try again...');\n          break;\n        }\n        // Expected error\n        case error.name === RAN_AWAY: {\n          const { direction } = bugsy.getMetadata(error);\n          console.log(`Oh well... I should head ${direction}`);\n          return;\n        }\n        // Unexpected error\n        default:\n          throw new bugsy.Bugsy({\n            name: CAPTURE,\n            message: 'Capture failed',\n            cause: error,\n            severity: 1,\n          });\n      }\n    }\n  }\n});\n```\n\n## License\n\n[MIT](license)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjakob%2Fbugsy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnjakob%2Fbugsy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnjakob%2Fbugsy/lists"}