• Stars
    star
    195
  • Rank 199,374 (Top 4 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Dump a heap snapshot upon an uncaught exception

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 <[email protected]>

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.

More Repositories

1

nightmare

A high-level browser automation library.
JavaScript
19,445
star
2

socrates

Write and read Markdown in real-time with anyone you want.
JavaScript
482
star
3

khaos

A super-simple way to scaffold new projects.
JavaScript
407
star
4

yal

Yet Another Logger — send logs to dedicated logging servers.
JavaScript
169
star
5

date-math

Math. functions for dates
JavaScript
166
star
6

highlight

A simple, pluggable API for syntax highlighting.
JavaScript
149
star
7

sheet

A special modal that slides out from the right or left side of the screen.
JavaScript
143
star
8

metrics

Simple and pluggable business metrics
JavaScript
91
star
9

hermes

A friendly, pluggable chat bot.
JavaScript
89
star
10

s3-dynamo-lambda

An example function showing how to count events from s3 in dynamo using lambda
JavaScript
77
star
11

herd

Herd your child processes: zero downtime reloads for node.js
JavaScript
73
star
12

nightmare-swiftly

Nightmare plugin for Swiftly.com
JavaScript
73
star
13

filter

Filter JSON streams using javascript.
Go
72
star
14

analytics.js-integrations

All of the third-party analytics.js integrations.
71
star
15

sse-stream

A Server-Sent Events transform stream
JavaScript
65
star
16

multipub

Clustered redis pub/sub
JavaScript
64
star
17

sse

A Server-Sent Events component
JavaScript
61
star
18

go-log

Go core-like logger with levels and default logger
Go
59
star
19

wildcards

Wildcard event emitter matching for nodejs
JavaScript
59
star
20

terraform-datadog

Go
57
star
21

google-spreadsheets

A nicer Google Spreadsheets API for node.
JavaScript
51
star
22

analytics-swift

The hassle-free way to add analytics to your Swift app.
Swift
50
star
23

csv

Uber simple CSV formatting/parsing for node
JavaScript
49
star
24

tableize

Generate a table-friendly object by flattening and normalizing the keys
JavaScript
48
star
25

metalsmith-templates

A metalsmith plugin to render files with templates.
JavaScript
46
star
26

yal-server

Extensible server for the YAL logger
JavaScript
43
star
27

toggle

A toggle UI element.
JavaScript
39
star
28

analytics-wordpress

[DEPRECATED] The hassle-free way to integrate analytics into any WordPress site.
PHP
39
star
29

serve

Tiny featureless Go file server – amaze.
Go
36
star
30

hn-button.com

The code behind the Hacker News button.
JavaScript
35
star
31

netx

Go package augmenting the standard net package with more basic building blocks for writing network applications.
Go
31
star
32

google-analytics

Query Google Analytics from node
JavaScript
31
star
33

go-map-path

Get map value via dot-delimited path or nil.
Go
29
star
34

koa-params

Add express style params support to koa
JavaScript
26
star
35

json_to_nsq

Publish newline-delimited JSON messages to an NSQ topic.
Go
26
star
36

loggly

Loggly client for node.js
JavaScript
26
star
37

concurrent-transform

Add some concurrency to a transform stream.
JavaScript
24
star
38

go-utils

Assortment of little Go utilities.
Go
23
star
39

integration-google-analytics

Google Analytics server-side integration
JavaScript
23
star
40

validate-schema

Validate an object against a redshift schema.
JavaScript
22
star
41

geckoboard

Geckoboard API for node.
JavaScript
22
star
42

auto-schema

Generate Redshift schemas from sample objects
JavaScript
21
star
43

backo-java

Exponential backoff for Java
Java
21
star
44

go-env

Go wrapper around os.Getenv() that returns an error instead of empty string
Go
21
star
45

tfe-state-explorer

Simple shell for exploring remote terraform enterprise state, with autocomplete.
Go
18
star
46

iphone-5-template

An HTML template for easily adding an iPhone rendering to your site, which you can then fill with your own content.
CSS
18
star
47

forward-events

Forward events from one emitter to another
JavaScript
17
star
48

go-start-nsq

Helper program to boot nsqd / nsqlookupd / nsqadmin nodes for local development
Go
17
star
49

raf-scroll

requestAnimationFrame for window scroll events
JavaScript
17
star
50

marketo-python

Marketo python library
Python
17
star
51

throttle

Tool for throttling JSON streams.
Go
17
star
52

consul-router

HTTP proxy with service discovery capabilities based on consul
Go
17
star
53

go-shipit

Proxy stdio for seamless local/remote logging
Go
17
star
54

view

Create reactive views.
JavaScript
16
star
55

analytics-magento

[DEPRECATED] The hassle-free way to integrate analytics into any Magento store.
PHP
15
star
56

superagent-csrf

Adds CSRF headers to client-side superagent requests
JavaScript
15
star
57

metrics-aws-billing

Visualize your AWS hosting costs on a dashboard
JavaScript
15
star
58

sherlock-segment

The core Segment integrations for Sherlock
JavaScript
15
star
59

co-event

Consume events from an event emitter in generators
JavaScript
14
star
60

go-mapped-csv

Write CSV mapped by column.
Go
13
star
61

errors

Simple abstraction to handle custom errors in your codebase.
JavaScript
13
star
62

loggly-cat

Stream logs to loggly via stdio.
Go
13
star
63

integration-facebook-app-events

The Facebook App Events server-side integration.
JavaScript
13
star
64

locale-string

Convert locale strings to english names and back
JavaScript
12
star
65

koa-request-id

Add a request id
JavaScript
12
star
66

monlog

MongoDB log server with human-friendly query language support
JavaScript
12
star
67

redis-lock

Node redis lock implementation for locking with a TTL.
JavaScript
12
star
68

component-jade

A plugin to transpile Jade files for the component builder.
JavaScript
12
star
69

metrics-stripe-subscriptions

Visualize your Stripe subscriptions and MRR over time on a dashboard.
JavaScript
12
star
70

form

Dynamically generate a form by adding fields from a schema.
JavaScript
12
star
71

analytics-c

The hassle-free way to integrate analytics into any C application.
C
11
star
72

khaos-node

A Khaos template for node.js modules.
JavaScript
11
star
73

npub

Publish a message to NSQ from the command-line
JavaScript
11
star
74

metrics-helpscout

Visualize your Helpscout activity on a dashboard
JavaScript
11
star
75

read-metadata

Load a JSON or YAML metadata file and return it as an object.
JavaScript
11
star
76

proxy-events

Use https://github.com/segmentio/forward-events instead.
JavaScript
10
star
77

component-sass

A plugin to transpile Sass files for the component builder.
JavaScript
10
star
78

to-transform

Create a transform stream constructor from a function
JavaScript
10
star
79

slug

The slugging function we use for Segment projects, usernames, etc.
JavaScript
10
star
80

mocha-broken

Only run previously broken mocha tests
JavaScript
10
star
81

metrics-express

Express server plugin for your business metrics
JavaScript
10
star
82

go-json-datatypes

Get JSON datatype for given value.
Go
10
star
83

go-dup

Dup an fd for a RW pipe
Go
10
star
84

segmentio.github.com

Parkour!
9
star
85

metrics-stripe-charges

Visualize Stripe charges over time.
JavaScript
9
star
86

nsq-manage

Manage nsqd instances
JavaScript
9
star
87

node-sass-wrapper

A wrapper around the command line Sass gem.
JavaScript
9
star
88

showable

Mixin for views to make them show and hide
JavaScript
9
star
89

source-postgres

Postgres database source -> Segment
Go
9
star
90

myth.io

The site for Myth, the pure CSS postprocessor.
CSS
9
star
91

metalsmith-prompt

A metalsmith plugin to prompt the user for series of answers and add them to the global metadata.
JavaScript
9
star
92

analytics-java-benchmark

Simple benchmark illustrating flushing mechanism of the java client
Java
8
star
93

hash-mod

Node module to hash strings into numbers and then mod them into buckets
JavaScript
8
star
94

gh

little github client
JavaScript
8
star
95

mockwebserver

Scriptable web server for testing HTTP clients.
Go
8
star
96

go-loggly-cli

Loggly search CLI written in Go
Go
7
star
97

node-json-to-dynamo

JavaScript
7
star
98

load-script-once

Load a Javascript file asynchronously if it hasn't been loaded.
JavaScript
7
star
99

overlay

A simple overlay UI component.
JavaScript
7
star
100

go-stathat

Stathat client with batching support.
Go
7
star