question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make stack traces more useful

See original GitHub issue

RxJS version: 5.4.0 Code to reproduce:

const { Observable } = require('rxjs');
function myBigActionChainBuilder(){
	//handle requests from the server, routing them to handlers in
	//different files depending on what url we are serving.
	return Observable.of({})
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => { return; })
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
		.mergeMap((state) => Observable.of(state))
}
myBigActionChainBuilder().subscribe(()=>{
	//do nothing
})

Feature Request:

When I run the above code, it gives me this error, which is expected.

TypeError: You provided ‘undefined’ where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

But the stack trace, even if I insert Error.stackTraceLimit = Number.MAX_SAFE_INTEGER;, only gives me the stack trace to my subscribe call. This is useless, as everyone has acknowledged, but I am surprised that no one has come up with an alternative. Therefore I would like to propose the solution that has worked very well for me.

Simply add this line to the Observable constructor this.conStack = new Error().stack;, and change the subscribe method so it looks like the below.

subscribe(observerOrNext, error, complete) {
	var operator = this.operator;
	var sink = toSubscriber(observerOrNext, error, complete);
//add this:
	if (sink) {
		const myErr = sink.error;
		const self = this;
		sink.error = function (err) {
			console.log('Observable error', err.message, self.conStack);
			return myErr.apply(this, arguments);
		}
	}
//to here
... the rest of subscribe ...

This returns a much more useful stack trace that points to the actual operator call where the error was thrown. Here is an example stack trace from different code than the one above. As you can see the 4th item in the trace is the method that caused the error.

Observable error You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. Error
    at new Observable                              (...\Rx.js:858:29)
    at ScalarObservable.Observable.lift            (...\Rx.js:871:33)
    at ScalarObservable.switchMap                  (...\Rx.js:13299:21)
    at $tw.boot.startup                            (...\boot.js:2125:27)
    at \boot.js:2434:12
    at $tw.boot.decryptEncryptedTiddlers           (...\boot.js:1468:2)
    at $tw.boot.boot [as boot]                     (...\boot.js:2432:11)
    at Object.<anonymous>                          (...\tiddlywiki.js:13:10)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
dummdidummcommented, Mar 3, 2020

According to the docs of rxjs v7 a goal is to make stack traces shorter. Could any of the implementers shed some light on how they want to achieve this? I know of the trx-branch which seems promising. Is this the planned way to go?

1reaction
Arlen22commented, Jul 11, 2017

Would it be possible to add a global variable of some sort that would allow this to be turned on or off?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making stack traces more useful with symbolication - Bugsnag
When debugging errors, symbolicated stack traces are essential because they provide visibility into where the errors originated in the code.
Read more >
Understanding and Leveraging the Java Stack Trace - Stackify
Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root...
Read more >
java - What is a stack trace, and how can I use it to debug my ...
A stacktrace is a very helpful debugging tool. It shows the call stack (meaning, the stack of functions that were called up to...
Read more >
Ten Tips for Using Java Stack Traces - InfoWorld
Stack traces can be extremely useful in debugging and understanding how an application works, but they are obviously less than effective if not ......
Read more >
Stack Traces in 3 Minutes - Medium
A stack trace is a list of functions called up to the point of an error · Stack trace should be read from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found