7 ms·
Goodbye “undefined is not a function”
- tosh 12y agoIt's available in Chrome Canary.
- sandstrom 12y agoThis is a great adjustment. Another one (which IE may have stopped doing in recent versions) is the annoying translation of exceptions. O servidor Automation não consegue criar o objeto -- anyone? :)
- ygra 12y agoIf you hate other languages so much, why not use English as your UI language, then?
- Zarel 12y agoI think "foo.bar is undefined, not a function" might be clearer.
- deleted 12y ago[deleted]
- schrijver 12y agoNot just clearer, transmits more information!
- kevan 12y agoThis would help a lot in case where you have multiple calls chained together. foo.bar().fiz().buz() What's undefined, bar, fiz, or buz? Then you have to set a breakpoint to find out. Most people I know try to avoid writing code like this, but Knockout ViewModels are a common place where this bites me.
- eyko 12y agoIf bar() or fiz() return undefined (i.e. don't return at all), then you will still get the same error as usual undefined is not an object, I reckon.
- saraid216 12y agoThe issue isn't that the functions are returning undefined. It's... foo = {} foo.bar() Or, more commonly, foo = {}; bar = 'bar'; foo[bar]();
- CmonDev 12y agoEven better: "Error, you are using JavaScript."
- codewithcheese 12y agoHappy to see someone is working on improving js error messages. This is a good example of why people hate Javascript.
- dkersten 12y agoWill this work with source maps?
- skybrian 12y agoSomeone should try it, but it seems unlikely if V8 is generating the error message. Dev Tools loads the source maps and as far as I know, V8 doesn't know about them.
- deleted 12y ago[deleted]
- azeirah 12y agoTypeError: (intermediate value)(...) is not a function (in firefox :^)
- PublicEnemy111 12y agoUncaught TypeError: (intermediate value)(intermediate value)(...) is not a function chrome canary
- robterrell 12y agoTypeError: undefined is not a function (evaluating 'foo.bar()') (for completeness, in Safari)
- saidajigumi 12y agoWhat version of FF are you on? I'm seeing this in FF 35.0.1: TypeError: foo.bar is not a function
- Aldo_MX 12y agoInternet Explorer has stopped working Windows is checking for a solution to the problem... [||||||||||||||||||||||||||||||||||||||||||||||||||] [ Cancel ]
- jordanthoms 12y agoThis is one of my pet peeves with most languages' error messages - e.g in Ruby: 2.2.0 :001 > a = nil; b = " "; c = "a"; 2.2.0 :002 > a + b + c NoMethodError: undefined method `+' for nil:NilClass from (irb):2 It would be trivial to tell me what the name of the nil variable was - in this case it's obvious, but it's often not.
- adrusi 12y agoExcept in Ruby, that error is raised by `NilClass#method_missing`. `method_missing` gets to know the name of the method being called, and the arguments passed to it, but it deals with the value, not the variable. It wouldn't be "trivial" to report the name of the variable, it would probably involve intercepting all NoMethodErrors raised by NilClass and then dropping into the debugger to know where exactly execution stopped. I'm not sure this is even possible with the current architecture of the Ruby interpreter.
- nilved 12y agohttp://ruby-doc.org//core-1.8.7/Kernel.html#method-i-caller http://ruby-doc.org//core-1.8.7/Kernel.html#method-i-caller https://github.com/banister/method_source https://github.com/banister/method_source
- paulirish 12y agoThis change required adding a pretty-printer into V8 to massage that AST back to something recognizable: https://codereview.chromium.org/861623002 https://codereview.chromium.org/861623002 Still, there are decent improvements we could make. Star, or better yet, comment on https://code.google.com/p/chromium/issues/detail?id=259443 https://code.google.com/p/chromium/issues/detail?id=259443 with how you get caught out by weak error messages. We want the debugging cycle to be a lot more direct from error to fix.
- tootie 12y agoCan it throw an exception when we're using a js library that isn't cool anymore?
- FLUX-YOU 12y agoExceptions as a service.js
- evilpie 12y agoSpiderMonkey has something that we call ExpressionDecompiler [1]. Basically it allows us to decompile some subset of the JS bytecode. Fun fact: At some point in time SpiderMonkey could actually decompile all bytecode and this is how we used to generate the result of Function#toString. [2] [1] https://dxr.mozilla.org/mozilla-central/search?q=ExpressionDecompiler https://dxr.mozilla.org/mozilla-central/search?q=ExpressionD... [2] https://bugzilla.mozilla.org/show_bug.cgi?id=718969 https://bugzilla.mozilla.org/show_bug.cgi?id=718969
- po 12y agoThank you. This will save so much development time globally. Please also look into the "Script error" message. I know it is intentionally non-descript to prevent leaking information about cross domain requests but there has to be something that is safe to report that will help developers narrow down what is causing it.
- jon-wood 12y agoGiven developers can usually narrow it down after a bit of trial and error I see no reason to obfuscate this. By its nature all the source is available to anyone asking, so let's just stop making CORS debugging such a pain.
- bsimpson 12y agoCertainly a great improvement, but it's sad that the WebKit Dev Tools are well over a decade old, and this change is just coming now. It shows how much room there is for improvement in developer ergonomics.
- criloz2 12y agoWow! thanks.. my hate towards JavaScript has been reduced dramatically with this update.
- bzbarsky 12y agoJavascript, or V8 and Chrome's devtools? Firefox has had sane error reporting in this situation for quite a long while....
- DigitalSea 12y agoThis has been one of the biggest annoyances of debugging Javascript I can think of. Maybe it is rather small to many, but this is a big deal for me and I cannot wait for it to land in the stable version of Chrome (even though I am a Firefox user), I still test in Chrome.
- deleted 12y ago[deleted]
- jfaucett 12y agoThis is awesome! If there's one area that still needs a lot of work in the js world I think its exception messages. Its hard to believe its 2015 and its still so hard get clean stack traces for your minified js in production since you can't source map it there. I wonder how large js apps handle production debugging and error reporting on all browsers? The last time I tried window.onerror it had decent support but not comprehensive support across browsers. Maybe its just me but this seems like a problem really needing to be solved, especially as js apps get bigger and bigger.
- breck 12y agoUse a query string to run an unminified version in prod.
- piotrkaminski 12y agoI just use https://getsentry.com/ https://getsentry.com/. Seems to work pretty well, both across browsers and with my minified code.
- TheAceOfHearts 12y agoWhy can't you use source maps in production?
- pimlottc 12y agoOP may be referring to jQuery's removal of the sourcemap comment last year, starting from 1.11/2.1 [0]. Basically, many sites deploy the minified library without the sourcemap, leading to tons of 404 errors which confuse users. 0: http://bugs.jquery.com/ticket/14415 http://bugs.jquery.com/ticket/14415
- woah 12y agoYou usually step through the code you were last working on and it's in there.
- drcode 12y agoFirst, I get a roomba, and now this... For those of you who argue that the US standard of living hasn't improved since the 70s: How do you defend your position in the face of this overwhelming counter-evidence?
- UnoriginalGuy 12y agoI'd just point to C++'s error output: http://www.codeproject.com/KB/cpp/791461/errors_temp.PNG http://www.codeproject.com/KB/cpp/791461/errors_temp.PNG
- iopq 12y agoI can't leave my socks on the floor anymore because Roomba will eat them.
- rtfeldman 12y agoThis is cool, although the title reminded me of one of my favorite parts of Elm[0]...I've effectively said goodbye to “undefined is not a function” because I've said goodbye to runtime exceptions in general. More specifically, I have yet to write Elm code that compiles and throws a runtime exception. I sure don't miss seeing "undefined is not a function!" A top-shelf compiler is a hell of a drug. :) [0] http://elm-lang.org http://elm-lang.org
- millstone 12y agoHow does Elm handle browser differences? For example, window.clipboardData.setData is only defined in IE, so what happens if I call it unconditionally from Elm, and am using Firefox?
- rtfeldman 12y agoDepends on what you're doing. In some cases Elm.Native will take care of browser differences. In general, Elm's replacement for the concept of undefined is Maybe, and the compiler will tell you if you forgot to handle something properly: http://elm-lang.org/edit/examples/Functional/Maybe.elm http://elm-lang.org/edit/examples/Functional/Maybe.elm
- millstone 12y agoAfter some research, it looks like my answer is that I can't call it unconditionally from Elm. Elm doesn't provide an easy way to access arbitrary JavaScript properties, and doesn't attempt to expose all of the functionality of the browser, but instead provides its own API.
- inglor 12y agoNot going to hijack the thread or anything - I'm just wondering why when I posted it yesterday it went relatively unnoticed? As someone who might have to do some startup marketting - what did I do wrong from a copyrighting point of view? Here is the post https://news.ycombinator.com/item?id=9087763 https://news.ycombinator.com/item?id=9087763
- zo1 12y agoWell, for one, the person that posted this link has 9-10 times more karma than you: karma: 4659 I'm a bit cynical, but I definitely think that had something to do with it if it wasn't just for the timing.
- chrisheller 12y agoI saw the original link on my phone yesterday. The screenshots in the post were unreadable since pinch and zoom was disabled, so I didn't fully understand until pulling up HN on a larger screen today. I have no idea how many other people might have read your submission on their phone and had the same issue though.
- DanBC 12y agoI never visit links to Twitter.
- viggity 12y agoIf you want something similar for .net, please consider upvoting this issue now that it is open source https://github.com/dotnet/coreclr/issues/25 https://github.com/dotnet/coreclr/issues/25
- evincarofautumn 12y agoI am certain that someone somewhere is relying on the old exception message, and that this change broke their code.
- acjohnson55 12y agoThey'll either be ready or they'll learn a valuable lesson.
- aerovistae 12y agoYESSSSŚŠSSSSSS
- martinko 12y agoIf we're lucky, this might make it into node by 2020!
- riffraff 12y agowhile this is awesome, doesn't it affect compatibility? i.e. if a library was checking the error message
- Gurkenmaster 12y agohttps://github.com/mattdiamond/fuckitjs https://github.com/mattdiamond/fuckitjs
- CmonDev 12y ago2015.
- bpg_92 12y agoThis is awesome! "undefined is not a function" was one big problem for me when I started cleaning up code, and didn't know what caused the issue, I spend a lot of time debugging.
- akennberg 12y agoCan we get a properly working window.onerror? Currently we either get a very generic Script Error (0 information for debugging) or have to wrap every native method in one with a try/catch. This is more for error log collection and aggregation to understand what's breaking in production.