oh-crap

1.1.0 • Public • Published

crap

Dump a heap snapshot upon an uncaught exception. Inspired by hapijs poop.

Installation

$ npm install oh-crap

Usage

This module exports a single function that when called, should be passed the directory where the heap snapshot should be written and also an optional error handler that will be passed the uncaught error after the heap snapshot is written.

It is recommended that you pass the optional error handler so that your application can log, cleanup and exit correctly. Otherwise the default error handler will simply exit the process.

var crap = require('oh-crap')(__dirname, onerror);
 
// message instance
var msg = new Message({
  name: 'yo',
  event: 'order complete',
  properties:{
    products: { '0': { sku: 'xxx' } }
  }
});
 
// cause an error
setTimeout(function(){
  msg.properties.products.forEach(console.log);
}, 250);
 
// handle the error
function onerror(err){
  console.error(err.stack);
  setTimeout(function(){
    console.error('exiting');
    process.exit(1);
  }, 1000);
}
 
// constructors make debugging life easier
function Message(obj){
  this.type = obj.type;
  this.event = obj.event;
  this.properties = obj.properties;
}

When running the example above, the uncaught exception TypeError: Object #<Object> has no method 'forEach' will be thrown. Since we have the snapshot written at the time of the uncaught exception, we can view the state of V8's heap using Google Chrome's heap profiler to answer the question you might thinking if this were production: "That's strange, if products isn't an array, I wonder what got assigned to it?"

Heap Snapshot Profile

License

The MIT License

Copyright © 2014, Segment.io <friends@segment.io>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i oh-crap

Weekly Downloads

9

Version

1.1.0

License

MIT

Last publish

Collaborators

  • ldelossantos
  • cjo2
  • achandrashekaran
  • aparna.singhal
  • ynguyen
  • timmyzsearcy
  • igracheva-twilio
  • yashnit-segment
  • nanotimm
  • srivig21
  • chenchensegmentcom
  • sanket.mishra
  • lweimersegment
  • rcheedhalla
  • jxin_twilio
  • odoren_segment
  • aditi.raveesh
  • dltnbrks-segment
  • sai-patanjali
  • himanshuph
  • alecjacobs-segment
  • sshaikh_segment
  • john.lee1100
  • dazu70
  • brian.aguirre
  • pooja.patil
  • segment_fan
  • nlubchenco
  • jamezhutwilio
  • knksmith57-segment
  • jsh-wu
  • nithin-benny
  • poojasegment
  • ebru.odok
  • bannapple
  • rodhilton_twilio
  • guthriesegment
  • srishti-nema
  • cdelaomartinez
  • miguelpdiaz8
  • sundareswar.jayakumar
  • gbatra
  • spencerattick
  • akodankiry
  • nanette.ranes
  • gsolis_segment
  • nitinpm432
  • aadityabhatt10
  • amigandhi
  • segmentsean
  • hmohanram_seg
  • jrupasinghe
  • myrontin.segment
  • devthale
  • smccoy-twilio
  • seg-leonelsanches
  • jibrang
  • sethgrid_segment
  • light-bringer-blr
  • aubreysine
  • ed-twilion-npm
  • harsh-joshi99
  • irfan.ali.segment
  • kbhargavaram-sg
  • needcaffeine
  • nat-grid
  • wlumsegment
  • vivek-26
  • moyara2
  • bala.singareddy
  • gbbastos
  • akash.gautam07
  • preetyp
  • viveksainaneesegment
  • msaraf
  • kjoerres
  • rokatyal
  • ainatancinco
  • anton-vylushchak
  • sowjanyasegment
  • alayvora
  • msaunders-segment
  • tw-dgarcia
  • parag.panda
  • blangtwilio
  • ryanrouleau-segment
  • twjosiah
  • mcullenmeyer
  • david.anusontarangkul.segment
  • mckern_segment
  • segment-admin
  • nainy.agrawal
  • tdibacco
  • sudojatin
  • nageshgolem
  • brandonheyer-segment
  • alfrimpong
  • dobrin.ganev
  • ankit.gupta.unthinkable
  • marinhero
  • benattwilio
  • bharath.boregowda
  • conniechen
  • sungju.jin
  • pooyaj
  • yli119
  • ea_segment
  • emilyjia
  • kx-segment
  • xinghao.huang
  • harsh.vardhan
  • joe.ayoub.segment
  • gkochar123
  • rollcode
  • ariel.silvestri
  • cherylj-segment
  • immanoj
  • aaronklish
  • michelr
  • maneesh.dharma29
  • msolorzano-segment
  • brianhumphreystwilio
  • jfehrman.segment
  • joetessy
  • pmunin
  • jalexy12
  • jbandi-twilio
  • prayansh-twilio
  • dominicbarnes
  • brandon.scott-segment
  • bgillan
  • phillip.thomas
  • ricardo.rossi
  • forgetfulfellow
  • fauzy.yy
  • mayur-pitale
  • dbaik-twilio-segment
  • seg-rustybailey
  • tanya.gupta.segment
  • pmiller-twilio
  • nevermore2022
  • aishikawaki
  • csayuso
  • mcoulibali
  • shupadhyay
  • jahood-twilio
  • saisagarkappaganthula
  • rmukundan
  • arubiochavez
  • shuvrajit9904
  • s3gm3nt
  • ama0223
  • tbrennanj
  • dangmai-segment
  • shraddha-twilio
  • azhaotwilio
  • sa-jsooter
  • enyi.asonye
  • afsha-nazim-seg
  • mschaszberger
  • lnamba
  • varadarajan-tw
  • seanhan-segment
  • replatero
  • sayan-das-in
  • justeen
  • sausingh
  • jgabe13
  • meg1000
  • funlu
  • ashwitha.bg
  • whaider_twilio
  • tcgilbert
  • kevinburkesegment
  • felttrip
  • prabhnoor1997
  • akashyap91
  • clintz.seg
  • karimkeshwani
  • wally.tg
  • rhall-twilio
  • yash-twilio
  • brookstaylorjr
  • shayan-golafshani
  • lerahulram
  • mugelstad
  • hdamani
  • rrivera-segment
  • sethnutetwilio
  • manali-bhosale
  • chtoombs
  • sethsegment
  • eric-hyde
  • elmoselyee
  • michaelghseg
  • jayakrishnannair
  • lateefat
  • maryam.sharif
  • wdbetts
  • ryanligon
  • sindhusegment
  • lfdelossantos
  • aramakrishnan
  • segment-camden
  • vbatanov
  • lluque-twilio
  • jair.aviles
  • pmaid
  • song4you
  • peterdemartini
  • emmy.byrne
  • vincen7tran
  • dean-huynh
  • cdignam-segment
  • abhinavsureka
  • arunlalam-segment
  • cjradek
  • neeharikakondipati
  • simpixelated
  • chihchun-twilio
  • acharles14
  • jyim008
  • hema-segment
  • oscb
  • krousseau
  • sachinwathore
  • fhalim-segment
  • cfree
  • hjoonpm
  • celine-segment
  • pmcanseco-segment
  • masira
  • amillet89
  • cholt002
  • av-segment
  • aghotikar
  • vikrant-segment
  • larryatsegment
  • ariel_segment
  • scruwys1
  • kyliepedersen
  • jinapark
  • segmentio
  • rajulvadera
  • lpediredla
  • n2parko
  • tyson_segment
  • bgamwell
  • uditmehta
  • salolivares
  • erikdw
  • chenxiangzhang
  • mericsson
  • prayansh-segmentt
  • jeremylarkin
  • bsneed
  • danieljackins
  • segment-seth
  • james9446
  • priscilla.giatti
  • nlsun
  • drew-thompson
  • segment-jsingh
  • andrius-segment
  • valerieernst
  • kelcook
  • gilomer
  • marcelopv
  • eric.rogner
  • kdharaiya
  • jon.anderson-at-segment.com
  • stacy.song
  • rexatsegment
  • nickaguilar
  • bradenbecker
  • reneewang
  • dan.lasky
  • sam.tapia
  • vikramkumar19
  • mpriyad25
  • jeremy.parker
  • smidges