17

I'm using the decorator to change the $exceptionHandler behavior, sending logs to the server. My problem with this is that the stackatrace of the exceptions seems useless, showing only part of the stack. For example:

Syntax Error: Token 'undefined' not a primary expression at column NaN of the expression [expression here].

at Error (native)
at throwError (http://localhost:8080/angular/angular.js:6674:62)
at primary (http://localhost:8080/angular/angular.js:6918:9)
at unary (http://localhost:8080/angular/angular.js:6900:14)
at multiplicative (http://localhost:8080/angular/angular.js:6883:16)
at additive (http://localhost:8080/angular/angular.js:6874:16)
at relational (http://localhost:8080/angular/angular.js:6865:16)
at equality (http://localhost:8080/angular/angular.js:6856:16)
at logicalAND (http://localhost:8080/angular/angular.js:6847:16)
at logicalOR (http://localhost:8080/angular/angular.js:6839:41)

Is there some way to configure AngularJS to show more stacks? If I look at Chrome console, I can see more stack, and get the filename, but not in the exception handler.

Even if I change the Error limit I cannot see the original file:

Error.stackTraceLimit = Infinity;
11
  • There is no known way to do this. Commented Jul 15, 2014 at 13:44
  • 1
    I was at Ng-Conf this winter and the angular team had a presentation on zone.js. I haven't looked into it so I don't know how relevant but perhaps worth exploring. thechangelog.com/zone-js (that is not my blog btw, just googled it up) Commented Jul 15, 2014 at 13:48
  • 1
    Are you throwing the error using 'throw new Error("error description")', or 'throw "error description"'? If you throw an Error object, it has more information available. Commented Sep 15, 2014 at 22:44
  • 1
    Can you provide here your implementation of $exceptionHandler decorator ? Commented Jul 30, 2015 at 17:23
  • 1
    thats one part of angular that really sucks....stack-traces are useless more than often Commented Sep 12, 2015 at 20:08

1 Answer 1

3

1 Use a debugger, instead of Chrome console

Google Chrome provides a debugger that helps JS programmers to find bugs and problematic code.

As the complexity of JavaScript applications increase, developers need powerful debugging tools to help quickly discover the cause of a issue and fix it efficiently. The Chrome DevTools include several useful tools to help make debugging JavaScript less painful.

You can try putting some breakpoints wherever you want (try to detect the problematic lines/ methods).

See the official documentation here: Google Chrome Debugger

2 Use a browser extension

Many plugins like ng-inspector or AngularJS Batarang helps you to print the status of your AngularJS program (controller instances, variable names/values, and scopes).

3 Use $log service (console.log wrapper)

The AngularJS $log service provides a simple resource to print the status of your variables in the browser console (if present).

Simple service for logging. Default implementation safely writes the message into the browser's console (if present).

The main purpose of this service is to simplify debugging and troubleshooting.

The default is to log debug messages. You can use ng.$logProvider#debugEnabled to change this. AngularJS $log service helps you to debug your program.


From my point of view, a good AngularJS debug includes the combination of all the above solutions.

I hope it is useful for you.

Sign up to request clarification or add additional context in comments.

7 Comments

The lack of stack trace makes debugging tools useless. If the OP knew the line number to place the breakpoint, I don't think he would be asking this question.
I'm not downvoting this answer because it still has useful information, but it doesn't really address the question. I also need a longer stack trace to determine what line in my code is generating the error. I suppose I might be able to use the debugger to step all the way back up to my code, but that feels pretty inefficient.
@rinogo Have you found a way to do this yet? I hate that I can't find what line of my code is causing the error
@Amon - I got nothin for ya. 😭 I think I just resorted to old-school “debugging” techniques like commenting out sections of code and placing calls to console.log throughout the code in question to hone in on the problem. Sorry I can’t help more!
@rinogo It's okay! I'm using the breakpoints in the debugger, why don't you use that? I was looking for the origin of an error I was getting in my code, but I actually think it's coming from an extension. According to the breakpoint, does that make sense?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.