Skip to content

Instantly share code, notes, and snippets.

@erkiesken
Last active February 24, 2016 20:51
Show Gist options
  • Save erkiesken/e03869b9d872e37df06c to your computer and use it in GitHub Desktop.
Save erkiesken/e03869b9d872e37df06c to your computer and use it in GitHub Desktop.
Disabling node repl util.inspect customInspect

When objects implement inspect method but its not meant for inspection then problems might occur.

For example with rxjs package:

> Rx = require("rxjs/Rx")
{ Subject: { [Function: Subject] create: [Function] },
  Observable:
…

> s = new Rx.Subject()
RangeError: Maximum call stack size exceeded
    at Subject.Observable (./node_modules/rxjs/Observable.js:21:24)
    at new Subject (./node_modules/rxjs/Subject.js:17:16)
    at Subject.lift (./node_modules/rxjs/Subject.js:28:23)

This is because Node's util.inspect will try to call s.inspect but that will recurse and throw an error.

Fix is to disable customInspect option for util.inspect as so:

let util = require("util");
let origInspect = util.inspect;
util.inspect = obj => origInspect(obj, { customInspect: false })

Now the same thing as above won't throw:

> s = new Rx.Subject()
Subject {
  _isScalar: false,
  destination: undefined,
…

The customInspect option is documented here.

@erkiesken
Copy link
Author

Opened RxJS issue #1387

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment