Will FP ever have a great Stack Trace story in JS?

Jason Kuhrt jasonkuhrt at me.com
Thu Sep 17 01:35:34 UTC 2015


Also I disagree with your assessment that I should go talk to the vendors. For example Axel R.’s recent post on Function names http://www.2ality.com/2015/09/function-names-es6.html <http://www.2ality.com/2015/09/function-names-es6.html> states in Section 2 the case where there is no name. I clarified on Twitter with him just now https://twitter.com/JasonKuhrt/status/644312567012323328 <https://twitter.com/JasonKuhrt/status/644312567012323328> that indeed the first ident assignment to an anon function will set its name. This is all thanks to JS 2015 not vendors (of course we need their compliance next).

So given the above in the future a compose function such as

```
let compose = (b, a) => (...as) => b(a(...as))
```

that is used like so:

```
const componentFactory = compose(React.createFactory, React.createClass)
```

Should have great stack trace support e.g.:

```
at componentFactory (/Users/jasonkuhrt/code/test/component-factory.js:1:36) 
```

So the reason I wrote this email is partially negated by Axel’s helpful information. However I’m still curious in any other thoughts trotting around for near or future about how to make the situation better around naming functions?


> On Sep 16, 2015, at 9:19 PM, James Kyle <me at thejameskyle.com> wrote:
> 
> Okay, let's break this down. Your example stack trace is really not a bad story.
> 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method.
> >     at invariant (/Users/jasonkuhrt/code/test/node_modules/react/lib/invariant.js:42:15)
> >     at ReactClass.createClass (/Users/jasonkuhrt/code/test/node_modules/react/lib/ReactClass.js:898:46)
> > 
> >     at /Users/jasonkuhrt/code/test/component-factory.js:4:41
> > 
> >     at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1)
> >     at Module._compile (module.js:434:26)
> >     at normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5)
> >     at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
> >     at Module.load (module.js:355:32)
> >     at Function.Module._load (module.js:310:12)
> >     at Function.Module.runMain (module.js:475:10)
> 
> 
> First off, you need to remove all the module loading-related stuff:
> 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method.
> >     at invariant (/Users/jasonkuhrt/code/test/node_modules/react/lib/invariant.js:42:15)
> >     at ReactClass.createClass (/Users/jasonkuhrt/code/test/node_modules/react/lib/ReactClass.js:898:46)
> > 
> >     at /Users/jasonkuhrt/code/test/component-factory.js:4:41
> > 
> >     at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1)
> 
> 
> Now, You're left with test code and the internal stack trace of React. Remove the React stuff and you have:
> 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method. 
> >     at /Users/jasonkuhrt/code/test/component-factory.js:4:41
> > 
> >     at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1)
> 
> 
> I'm assuming that 2nd item is just the test itself so let's kill that too.
> 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method. 
> >     at /Users/jasonkuhrt/code/test/component-factory.js:4:41
> 
> 
> So your error is around line 4 of `/code/test/component-factory.js`, and the error is that you created a React class without a render method.
> 
> I don't see what was bad about that, you certainly wouldn't want remove any of that stack trace as it's all real operations that might need debugging.
> 
> I also don't see what this has to do with your FP example of:
> 
> 
> > ```
> > let compose = (b, a) => (...as) => b(a(...as))
> > ```
> 
> 
> As that's clearly not the issue in your stack trace.
> 
> Also, if you want these stack traces to be more meaningful, you should be talking to the JavaScript engine implementor. In your case v8 (since you're using Node).
> 
> 
>> This email brought to you by the letters T, J, and K.
> 
> 
> On Wed, Sep 16, 2015 at 5:16 PM, Jason Kuhrt <jasonkuhrt at me.com <mailto:jasonkuhrt at me.com>> wrote:
> 
> For example, today, a stone from the bedrock of FP: 
> 
> > ``` 
> > let compose = (b, a) => (...as) => b(a(...as)) 
> > ``` 
> 
> will cause a JS Stack Trace to go from something useful (space around useful line) like: 
> 
> > ``` 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method. 
> 
> > at invariant (/Users/jasonkuhrt/code/test/node_modules/react/lib/invariant.js:42:15) 
> 
> > at ReactClass.createClass (/Users/jasonkuhrt/code/test/node_modules/react/lib/ReactClass.js:898:46) 
> 
> > 
> 
> > at componentFactory (/Users/jasonkuhrt/code/test/component-factory.js:1:36) 
> 
> > 
> 
> > at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1) 
> > at Module._compile (module.js:460:26) 
> > at normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5) 
> > at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7) 
> > at Module.load (module.js:355:32) 
> > at Function.Module._load (module.js:310:12) 
> > at Function.Module.runMain (module.js:501:10) 
> 
> > ``` 
> 
> To something much less useful like this: 
> 
> > ``` 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method. 
> > at invariant (/Users/jasonkuhrt/code/test/node_modules/react/lib/invariant.js:42:15) 
> > at ReactClass.createClass (/Users/jasonkuhrt/code/test/node_modules/react/lib/ReactClass.js:898:46) 
> > 
> > at /Users/jasonkuhrt/code/test/component-factory.js:4:41 
> > 
> > at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1) 
> > at Module._compile (module.js:434:26) 
> > at normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5) 
> > at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7) 
> > at Module.load (module.js:355:32) 
> > at Function.Module._load (module.js:310:12) 
> > at Function.Module.runMain (module.js:475:10) 
> 
> > ``` 
> 
> And ultimately being in a real-life scenario/library/etc. (e.g. Ramda compose) leading to something almost useless: 
> 
> > ``` 
> 
> > Error: Invariant Violation: createClass(...): Class specification must implement a `render` method. 
> > at invariant (/Users/jasonkuhrt/code/test/node_modules/react/lib/invariant.js:42:15) 
> > at ReactClass.createClass (/Users/jasonkuhrt/code/test/node_modules/react/lib/ReactClass.js:898:46) 
> > 
> > at /Users/jasonkuhrt/code/test/node_modules/ramda/dist/ramda.js:384:35 
> > at f1 (/Users/jasonkuhrt/code/test/node_modules/ramda/dist/ramda.js:156:27) 
> > 
> > at Object.<anonymous> (/Users/jasonkuhrt/code/test/test.js:4:1) 
> > at Module._compile (module.js:434:26) 
> > at normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5) 
> > at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7) 
> > at Module.load (module.js:355:32) 
> > at Function.Module._load (module.js:310:12) 
> 
> > ``` 
> _______________________________________________ 
> es-discuss mailing list 
> es-discuss at mozilla.org 
> https://mail.mozilla.org/listinfo/es-discuss 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150916/baaba216/attachment-0001.html>


More information about the es-discuss mailing list