{"id":15646468,"url":"https://github.com/martinheidegger/extend-stack","last_synced_at":"2026-05-05T05:34:41.761Z","repository":{"id":143879073,"uuid":"161590271","full_name":"martinheidegger/extend-stack","owner":"martinheidegger","description":"Two util methods extendStack and extendCb that make it easier to track async errors in callback systems.","archived":false,"fork":false,"pushed_at":"2021-05-14T06:09:32.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T00:42:03.314Z","etag":null,"topics":["async","callback","error","nodejs","stack","v8"],"latest_commit_sha":null,"homepage":"","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/martinheidegger.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":"2018-12-13T05:49:36.000Z","updated_at":"2021-05-14T06:10:34.000Z","dependencies_parsed_at":"2024-02-06T06:45:51.179Z","dependency_job_id":null,"html_url":"https://github.com/martinheidegger/extend-stack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fextend-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fextend-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fextend-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/martinheidegger%2Fextend-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/martinheidegger","download_url":"https://codeload.github.com/martinheidegger/extend-stack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254149,"owners_count":20747949,"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":["async","callback","error","nodejs","stack","v8"],"created_at":"2024-10-03T12:13:00.471Z","updated_at":"2026-05-05T05:34:36.740Z","avatar_url":"https://github.com/martinheidegger.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# extend-stack\n\n`extend-stack` offers two util methods `extendStack` and `extendCb` that make it easier\nto track async errors in callback systems.\n\n[![Build Status](https://travis-ci.org/martinheidegger/extend-stack.svg?branch=master)](https://travis-ci.org/martinheidegger/extend-stack)\n\n## Installation and Setup\n\n```shell\n$ npm install extend-stack\n```\n\n`extend-stack` is **disabled by default** because it consumes quite a bit of resources to work.\nTo enable it you need enable [debug][debug-wiki] either when calling your code…\n\n```shell\n$ env DEBUG=extend-stack node myapp.js # mac variant!\n```\n\n…or programmatically − after adding `$ npm install debug` − like this…\n\n```javascript\nconst debug = require('debug')\ndebug.enable('extend-stack')\n```\n\n[debug-wiki]: https://github.com/visionmedia/debug#windows-command-prompt-notes\n\n## Usage\n\nThe two methods are exposed as object:\n\n```javascript\nconst { extendStack, extendCb } = require('extend-stack')\n```\n\n### `extendCb(function (err, data) {})` → `function (err, data) {}`\n\n`extendCb` adds the error stack of the calling function in case an error\noccurs.\n\n```javascript\nconst fs = require('fs')\n\nsetImmediate(() =\u003e {\n  fs.readFile('non-existing', extendCb((err) =\u003e {\n    console.log(err.stack)\n  }))\n})\n```\n\n\u003cdiv\u003e\u003cem\u003e(disabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: ENOENT: no such file or directory, open 'non-existing'\n```\n\n\u003cdiv\u003e\u003cem\u003e(enabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: ENOENT: no such file or directory, open 'non-existing'\n    at Immediate.setImmediate (/extend-stack/examples/extendCb.js:5:31)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n```\n\nIf the error contains a stack, the stack will be part of it:\n\n```javascript\nconst { extendCb } = require('..')\n\nfunction errorProne (cb) {\n  setImmediate(() =\u003e cb(new Error('sample-error')))\n}\n\nfunction userFunction () {\n  errorProne(\n    extendCb(err =\u003e console.log(err.stack))\n  )\n}\n\nsetImmediate(userFunction)\n```\n\n\u003cdiv\u003e\u003cem\u003e(disabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: sample-error\n    at Immediate.setImmediate [as _onImmediate] (/extend-stack/examples/extendCb-withStack.js:4:25)\n    at runCallback (timers.js:705:18)\n    at tryOnImmediate (timers.js:676:5)\n    at processImmediate (timers.js:658:5)\n```\n\n\u003cdiv\u003e\u003cem\u003e(enabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: sample-error\n    at Immediate.userFunction (/extend-stack/examples/extendCb-withStack.js:9:5)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n    caused by:\n    at Immediate.setImmediate (/extend-stack/examples/extendCb-withStack.js:4:25)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n```\n\n### `extendStack(err, [offset])` → `Error`\n\n`extendStack` extends the stack stored in `err` and adds the current line's stack as well.\n\n```javascript\nconst { extendStack } = require('..')\n\nfunction subsystem (err) {\n  return extendStack(err)\n}\n\nsetImmediate(() =\u003e {\n  const err = subsystem(new Error('some-error'))\n  console.log(err)\n})\n```\n\n\u003cdiv\u003e\u003cem\u003e(disabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: some-error\n    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:25)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n```\n\n\u003cdiv\u003e\u003cem\u003e(enabled)\u003c/em\u003e\u003c/div\u003e\n\n```\nError: some-error\n    at subsystem (/extend-stack/examples/extendStack.js:4:10)\n    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:15)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n    caused by:\n    at Immediate.setImmediate (/extend-stack/examples/extendStack.js:8:25)\n    at runCallback (timers.js:789:20)\n    at tryOnImmediate (timers.js:751:5)\n    at processImmediate [as _immediateCallback] (timers.js:722:5)\n```\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fextend-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmartinheidegger%2Fextend-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmartinheidegger%2Fextend-stack/lists"}