> On Sep 28, 2014, at 8:01 AM, Marius Gundersen <[email protected]> wrote:
> 
> It would be helpful if the stack trace was machine readable, not just human 
> readable. As Erik said

+1

> 
> [...] we might ass well stop using a string to represent this structured data.
> 
> The stacktrace should probably be an array of objects with the properties 
> `filename`, `function`, `line` and `column`. It would then be simple to 
> format this stacktrace as a string and make it look exactly like it does in 
> browsers today. With a machine readable stack trace it would be easier to 
> build editor sandboxes (jsbin, codepen.io <http://codepen.io/>, etc) where 
> errors inside the sandbox could be caught by the editor and shown to the user.
> 
> Another feature of the stacktrace as an array is that a library could 
> manipulate the stack trace after it has been thrown, to hide the internals of 
> the library. This is similar to the black box feature in the Firefox 
> devtools. For example, a divide function which takes two integers could throw 
> an error when the second parameter is 0 (can't divide by zero). This would 
> result in the library internals ending up in the stack trace:
> 
> ```js
> function calculate(x, y){
>   return myIntegerMathLibrary.divide(2, x)*y;
> }
> 
> calculate(0, 5) 
> /*
> Exception: Second parameter is '0'; can't divide by zero
> divide@myIntegerMathLibrary/divide.js:15:15 <= this is library code,it's not 
> helpful to the developer
> calculate@myApplication:2:3 <= this tells the developer where the problem is 
> in their code
> @myApplication:4:1
> */
> ```
> 
> If the library was allowed to manipulate the stack of the Error object before 
> throwing it, it could remove the top n lines that are internal to it, which 
> would help the developer locate the issue in their code. 
> 
> Since all modern browsers implement a non-standard stack trace it is possible 
> to find out what file you are in and what line you are on by throwing and 
> catching an exception and analyzing the stack string. If stack traces are 
> added to the standard, then maybe a reflection API that can tell what file 
> and line the code is on should be added as well. The module meta object will 
> most likely get a filename property, but line number/character number is not 
> yet available.
> 
> Marius Gundersen
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to