{"id":13535590,"url":"https://github.com/sindresorhus/loud-rejection","last_synced_at":"2025-05-15T16:02:41.220Z","repository":{"id":55415329,"uuid":"43604481","full_name":"sindresorhus/loud-rejection","owner":"sindresorhus","description":"Make unhandled promise rejections fail loudly instead of the default silent fail","archived":false,"fork":false,"pushed_at":"2021-01-24T17:31:53.000Z","size":42,"stargazers_count":280,"open_issues_count":0,"forks_count":24,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-31T20:06:38.272Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-10-03T15:54:03.000Z","updated_at":"2025-01-07T20:11:14.000Z","dependencies_parsed_at":"2022-08-14T23:50:38.779Z","dependency_job_id":null,"html_url":"https://github.com/sindresorhus/loud-rejection","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Floud-rejection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Floud-rejection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Floud-rejection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Floud-rejection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/loud-rejection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492833,"owners_count":20947593,"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-08-01T08:00:59.895Z","updated_at":"2025-04-07T21:11:16.885Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://sindresorhus.com/donate","https://tidelift.com/subscription/pkg/npm-loud-rejection?utm_source=npm-loud-rejection\u0026utm_medium=referral\u0026utm_campaign=readme"],"categories":["JavaScript","Packages","包","目录","Command-line utilities","Convenience Utilities"],"sub_categories":["Command-line utilities","命令行工具","sindresorhus's many Promise utilities ([see notes](https://github.com/sindresorhus/promise-fun))","sindresorhus's many Promise utilities (\u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;5146⭐\u003c/code\u003e\u003c/b\u003e \u003cb\u003e\u003ccode\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;138🍴\u003c/code\u003e\u003c/b\u003e [see notes](https://github.com/sindresorhus/promise-fun)))"],"readme":"# loud-rejection\n\n\u003e Make unhandled promise rejections fail loudly instead of the default [silent fail](https://gist.github.com/benjamingr/0237932cee84712951a2)\n\nBy default, promises fail silently if you don't attach a `.catch()` handler to them.\n\nThis tool keeps track of unhandled rejections globally. If any remain unhandled at the end of your process, it logs them to STDERR and exits with code 1.\n\nUse this in top-level things like tests, CLI tools, apps, etc, **but not in reusable modules.**\u003cbr\u003e\nNot needed in the browser as unhandled rejections are shown in the console.\n\n**With [Node.js 15](https://medium.com/@nodejs/node-js-v15-0-0-is-here-deb00750f278), this package is moot as the default behavior then is to throw on unhandled rejections.**\n\n\n## Install\n\n```\n$ npm install loud-rejection\n```\n\n\n## Usage\n\n```js\nconst loudRejection = require('loud-rejection');\nconst promiseFunction = require('promise-fn');\n\n// Install the `unhandledRejection` listeners\nloudRejection();\n\npromiseFunction();\n```\n\nWithout this module it's more verbose and you might even miss some that will fail silently:\n\n```js\nconst promiseFunction = require('promise-fn');\n\nfunction error(error) {\n\tconsole.error(error.stack);\n\tprocess.exit(1);\n}\n\npromiseFunction().catch(error);\n```\n\n### Register script\n\nAlternatively to the above, you may simply require `loud-rejection/register` and the unhandledRejection listener will be automagically installed for you.\n\nThis is handy for ES2015 imports:\n\n```js\nimport 'loud-rejection/register';\n```\n\n\n## API\n\n### loudRejection([log])\n\n#### log\n\nType: `Function`\u003cbr\u003e\nDefault: `console.error`\n\nCustom logging function to print the rejected promise. Receives the error stack.\n\n\n## Related\n\n- [hard-rejection](https://github.com/sindresorhus/hard-rejection) - Make unhandled promise rejections fail hard right away instead of the default silent fail\n- [More…](https://github.com/sindresorhus/promise-fun)\n\n\n---\n\n\u003cdiv align=\"center\"\u003e\n\t\u003cb\u003e\n\t\t\u003ca href=\"https://tidelift.com/subscription/pkg/npm-loud-rejection?utm_source=npm-loud-rejection\u0026utm_medium=referral\u0026utm_campaign=readme\"\u003eGet professional support for this package with a Tidelift subscription\u003c/a\u003e\n\t\u003c/b\u003e\n\t\u003cbr\u003e\n\t\u003csub\u003e\n\t\tTidelift helps make open source sustainable for maintainers while giving companies\u003cbr\u003eassurances about security, maintenance, and licensing for their dependencies.\n\t\u003c/sub\u003e\n\u003c/div\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Floud-rejection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Floud-rejection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Floud-rejection/lists"}