{"id":21405346,"url":"https://github.com/karimsa/trashcan","last_synced_at":"2026-01-03T14:09:58.691Z","repository":{"id":30924580,"uuid":"34482515","full_name":"karimsa/trashcan","owner":"karimsa","description":"safe error handling in production environments","archived":false,"fork":false,"pushed_at":"2016-06-04T16:50:08.000Z","size":379,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-11T21:03:58.607Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karimsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-23T21:28:18.000Z","updated_at":"2016-04-23T22:20:32.000Z","dependencies_parsed_at":"2022-08-02T21:45:31.866Z","dependency_job_id":null,"html_url":"https://github.com/karimsa/trashcan","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Ftrashcan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Ftrashcan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Ftrashcan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Ftrashcan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karimsa","download_url":"https://codeload.github.com/karimsa/trashcan/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243902293,"owners_count":20366259,"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-11-22T16:24:21.784Z","updated_at":"2026-01-03T14:09:58.657Z","avatar_url":"https://github.com/karimsa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trashcan\n\nSafe error handling in production mode.\n\n[![NPM](https://nodei.co/npm/trashcan.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/trashcan/)\n\n## Usage\n\nInstall via npm (`npm install --save trashcan`) and then take advantage of the API to catch and handle errors.\n\n## Table of Contents\n\nAside from the auto-catching `uncaughtException` events on `process`, trashcan is useful for making sure the exception doesn't get that far.\nUse it in your code to not worry about errors in every callback you make.\n\n*Unless otherwise specified, all trashcan methods should be chainable. So you can do a lot of error handling at once, if you wish. For a more\ndetailed spec, see [the github page](https://ohdb.github.io/trashcan).*\n\n - [Error Handling](#error-handling)\n - [Asynchronous Callback Errors](#asynchronous-callbacks)\n - [Synchronous Errors](#synchronous-errors)\n - [Error Events](#error-events)\n - [Promise Rejections](#promise-rejections)\n - [Custom Errors](#custom-errors)\n\n### Error Handling\n\n```javascript\nvar tc = require('trashcan')\n\n// handle the errors manually\ntc.on('error', function (err) {\n  // do stuff with the error\n})\n\n// or auto-email the admin\ntc.on('error', tc.notify('me@email.com'))\n\n// or to a server log\ntc.on('error', tc.log('./server.log'))\n```\n\n*tc.notify() uses nodemailer in the background, and can either be passed nodemailer transport configuration as the second argument or that\nconfiguration can be saved into a file called `.mailrc` in your project folder.*\n\n### Asynchronous Callback Errors\n\n```javascript\nvar tc = require('trashcan')\n  , fs = require('fs')\n\nfs.readFile('./my-file.txt', 'utf8', tc(function (data) {\n  // handle file data\n}))\n```\n\n### Synchronous Errors\n\n```javascript\nvar tc = require('trashcan')\n  , fs = require('fs')\n\ntc(function () {\n  var data = fs.readFileSync('./my-file.txt', 'utf8')\n\n  // handle file data\n}).exec(function (err) {\n  // optional error handler\n  // (error will be thrown through trashcan\n  //  before this function is called)\n})\n```\n\n### Error Events\n\n```javascript\nvar tc = require('trashcan')\n  , http = require('http').Server(function () { /* server logic */ })\n\n// grab all errors from the server\ntc.catch(http)\n```\n\n### Promise Rejections\n\n```javascript\nvar tc = require('trashcan')\n\n// grab your promise, however\nvar promise = require('q').defer()\n\n// pass it forwards\ntc.swear(promise, function ( /* arguments */ ) {\n  // handle success\n})\n```\n\n### Custom Errors\n\n```javascript\nvar tc = require('trashcan')\n\n// throw the error manually\ntc.throw(trash)\n```\n\n## License\n\nGPLv3.\n\n```\ntrashcan: safe error handling in production mode.\nCopyright (C) 2015 Online Health Database\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarimsa%2Ftrashcan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarimsa%2Ftrashcan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarimsa%2Ftrashcan/lists"}