{"id":13847060,"url":"https://github.com/nickuraltsev/composite-error","last_synced_at":"2025-07-12T08:31:15.380Z","repository":{"id":33728775,"uuid":"37383102","full_name":"nickuraltsev/composite-error","owner":"nickuraltsev","description":"Error wrapping in Node.js","archived":false,"fork":false,"pushed_at":"2017-03-30T04:33:57.000Z","size":14,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-15T00:51:59.199Z","etag":null,"topics":["error-handling","error-wrapping","errors","inner-errors","stack-traces"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/nickuraltsev.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":"2015-06-13T18:32:56.000Z","updated_at":"2023-09-04T01:41:46.000Z","dependencies_parsed_at":"2022-09-18T00:42:15.311Z","dependency_job_id":null,"html_url":"https://github.com/nickuraltsev/composite-error","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nickuraltsev/composite-error","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickuraltsev%2Fcomposite-error","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickuraltsev%2Fcomposite-error/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickuraltsev%2Fcomposite-error/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickuraltsev%2Fcomposite-error/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nickuraltsev","download_url":"https://codeload.github.com/nickuraltsev/composite-error/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nickuraltsev%2Fcomposite-error/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264962126,"owners_count":23689741,"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":["error-handling","error-wrapping","errors","inner-errors","stack-traces"],"created_at":"2024-08-04T18:00:53.407Z","updated_at":"2025-07-12T08:31:15.089Z","avatar_url":"https://github.com/nickuraltsev.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# composite-error\n\n[![npm version](https://badge.fury.io/js/composite-error.svg)](https://badge.fury.io/js/composite-error)\n\n'composite-errors' allows you to wrap and re-throw an error, providing additional context without losing the original error information.\n\n## Overview\n\n- You can wrap one or multiple errors into a `CompositeError`.\n- You can use the `CompositeError` class as a base class for your own custom errors that can wrap other errors.\n- The `stack` property of a `CompositeError` returns a string containing the stack trace of the `CompositeError` and the stack traces of the wrapped errors.\n\n## Installation\n\n```\n$ npm install --save composite-error\n```\n\n## Usage\n\n### Wrapping an error\n\n```javascript\nconst CompositeError = require('composite-error');\n\ntry {\n  doSomething();\n} catch (error) {\n  throw new CompositeError('Error occurred while trying to do something.', error);\n}\n```\n\n### Wrapping multiple errors\n\n```javascript\nthrow new CompositeError('Multiple errors occurred', [error1, error2]);\n```\n\n### Creating custom errors\n\nUsing the ES2015 class syntax:\n\n```javascript\nclass MyCustomError extends CompositeError {\n  constructor(message, innerErrors) {\n    super(message, innerErrors);\n    this.name = 'MyCustomError';\n  }\n}\n```\n\nNot using the ES2015 class syntax:\n\n```javascript\nconst util = require('util');\n\nfunction MyCustomError(message, innerErrors) {\n  CompositeError.call(this, message, innerErrors);\n  this.name = 'MyCustomError';\n}\n\nutil.inherits(MyCustomError, CompositeError);\n```\n\n### Stack trace\n\nThe `stack` property of a `CompositeError` returns a string containing the stack trace of the `CompositeError` and the stack traces of the wrapped errors.\n\nFor example, the following code\n\n```javascript\nconst firstError = new Error('First error');\nconst secondError = new CompositeError('Second error', firstError);\nconst thirdError = new CompositeError('Third error', secondError);\nconsole.log(thirdError.stack);\n```\n\nwill produce the following output:\n\n```\nCompositeError: Third error\n    at Object.\u003canonymous\u003e (/Users/nick/Projects/composite-error/example1.js:7:18)\n    at Module._compile (module.js:460:26)\n    at Object.Module._extensions..js (module.js:478:10)\n    [... snipped for brevity ...]\n--- Inner error: CompositeError: Second error\n    at Object.\u003canonymous\u003e (/Users/nick/Projects/composite-error/example1.js:6:19)\n    at Module._compile (module.js:460:26)\n    at Object.Module._extensions..js (module.js:478:10)\n    [... snipped for brevity ...]\n--- Inner error: Error: First error\n    at Object.\u003canonymous\u003e (/Users/nick/Projects/composite-error/example1.js:5:18)\n    at Module._compile (module.js:460:26)\n    at Object.Module._extensions..js (module.js:478:10)\n    [... snipped for brevity ...]\n--- End of inner error\n--- End of inner error\n```\n\n### Accessing inner errors\n\nThe inner errors can be accessed using the `CompositeError#innerErrors` property.\n\n## License\n\n[MIT](https://github.com/nickuraltsev/composite-error/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickuraltsev%2Fcomposite-error","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnickuraltsev%2Fcomposite-error","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnickuraltsev%2Fcomposite-error/lists"}