{"id":20711585,"url":"https://github.com/mvaldesdeleon/long-promise","last_synced_at":"2025-04-23T06:46:57.108Z","repository":{"id":57290671,"uuid":"93091901","full_name":"mvaldesdeleon/long-promise","owner":"mvaldesdeleon","description":"Long stack traces for Promises (Node 8 only).","archived":false,"fork":false,"pushed_at":"2017-06-02T08:53:41.000Z","size":14,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T06:46:47.014Z","etag":null,"topics":["async-hooks","node","promise","stack","stacktrace"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mvaldesdeleon.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":"2017-06-01T19:23:51.000Z","updated_at":"2019-04-12T20:15:20.000Z","dependencies_parsed_at":"2022-08-28T05:52:38.515Z","dependency_job_id":null,"html_url":"https://github.com/mvaldesdeleon/long-promise","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/mvaldesdeleon%2Flong-promise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvaldesdeleon%2Flong-promise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvaldesdeleon%2Flong-promise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mvaldesdeleon%2Flong-promise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mvaldesdeleon","download_url":"https://codeload.github.com/mvaldesdeleon/long-promise/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250386745,"owners_count":21422026,"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-hooks","node","promise","stack","stacktrace"],"created_at":"2024-11-17T02:16:10.785Z","updated_at":"2025-04-23T06:46:57.082Z","avatar_url":"https://github.com/mvaldesdeleon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# long-promise\n\nLong stack traces with Promises, using the brand-new `async_hooks` API provided by Node 8.0.0.\n\n```JS\nconst lp = require('long-promise');\n\nlp.enable();\n\n// Simulate some stuff\nconst stuff = x =\u003e 2 + x;\n\n// Simulate a delay.\nconst delay = ms =\u003e x =\u003e {\n    // This function is `buggy` and will throw if the delay is 100ms.\n    if (ms === 100) throw new Error('boom');\n\n    return new Promise(res =\u003e {\n        setTimeout(() =\u003e {\n            res(x);\n        }, ms);\n    });\n};\n\nconst nestedProblems = x =\u003e () =\u003e {\n    // After the third call, go to an eventual `delay(100)` that throws\n    if (x === 3) return Promise.resolve(1).then(delay(100));\n\n    // Promise chain with recursion\n    return Promise.resolve(1)\n        .then(delay(10))\n        .then(stuff)\n        .then(nestedProblems(x + 1));\n};\n\n// Main program\nfunction run() {\n    const p = Promise.resolve(2);\n\n    // Do some things. Something along this promise chain will throw.\n    p.then(stuff)\n        .then(delay(10))\n        .then(stuff)\n        .then(delay(10))\n        .then(stuff)\n        .then(nestedProblems(1))\n        .then(stuff)\n        .then(stuff)\n        .catch(err =\u003e {\n            console.log(lp.getLongStack(err));\n            // Profit\n        });\n}\n\nrun();\n```\n\nThis produces the following stack trace:\n\n```\nError: boom\n    at x (/Users/mvaldes/Sandbox/long-promise/example.js:12:27)\n    at \u003canonymous\u003e\n    at Promise.then (\u003canonymous\u003e)\n    at /Users/mvaldes/Sandbox/long-promise/example.js:23:44\n    at \u003canonymous\u003e\n    at Promise.then (\u003canonymous\u003e)\n    at /Users/mvaldes/Sandbox/long-promise/example.js:29:10\n    at \u003canonymous\u003e\n    at Promise.then (\u003canonymous\u003e)\n    at /Users/mvaldes/Sandbox/long-promise/example.js:29:10\n    at \u003canonymous\u003e\n    at Promise.then (\u003canonymous\u003e)\n    at run (/Users/mvaldes/Sandbox/long-promise/example.js:42:10)\n    at Object.\u003canonymous\u003e (/Users/mvaldes/Sandbox/long-promise/example.js:51:1)\n    at Module._compile (module.js:569:30)\n    at Object.Module._extensions..js (module.js:580:10)\n```\n\nWithout `long-promise` enabled, the original stack trace is the following:\n\n```\nError: boom\n    at x (/Users/mvaldes/Sandbox/long-promise/example.js:12:27)\n    at \u003canonymous\u003e\n```\n\nThis is very early work, any contributions are welcome.\n\n# install\nwith [npm](https://npmjs.org) do:\n\n```\nnpm install long-promise\n```\n\n# license\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvaldesdeleon%2Flong-promise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmvaldesdeleon%2Flong-promise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmvaldesdeleon%2Flong-promise/lists"}