Well this is a real problem because when you are a module author people call things that don't exist, and those things can be called within the context of your library.
Solutions don't exist, domains will tackle a bit of this problem and mature to a better solution. Still in the works, see http://nodeup.com/fifteen There are solutions if you "own" the code (https://github.com/pgte/bubble, https://github.com/substack/node-toss) Personally I found a way of doing this using uncaughtException but only if you serialize function calls. This way you can keep the ""stack"" (read, variables that matter to the execution of your program) and attach the uncaught handler just before the critical section, that is when you execute the code that was passed to your library. You then release the uncaught handler, cause you really should try to avoid it as much as you can. Here is where I implemented this: - https://github.com/dscape/specify/blob/master/specify.js#L145 This is super specific, it's ok for testing but not so sure about other uses (and potential abuse) so I didn't publish a module. Nuno On Mon, Mar 26, 2012 at 4:29 PM, Roly Fentanes <[email protected]> wrote: > Don't make a call to a module function which doesn't exist. > > I really don't see this as being an actual problem. Read the module > documentation, they'll tell you what the module exposes. If you're worried > about it's API changing and getting a different version when deploying, use > stricter version ranges. > > > On Monday, March 26, 2012 7:49:57 AM UTC-7, 0x80 wrote: >> >> I am standardizing all my callbacks to do proper exception handling, but >> the only type of exceptions I can't seem to catch in a good way are the >> ones illustrated below. When I make a call to a module function which >> doesn't exist the exception is not caught anywhere even though I have the >> uncaughtExeption handler. >> >> Can anyone explain my what is the best way to catch this, and why this >> exception isn't reported to me? The only solution I found is to put a >> try/catch phrase around the module function call, but this is not a proper >> solution, because you make these kind of errors by accident. I don't want >> to put a try/catch clause around every module function I call just to make >> sure i don't have a typo. >> >> These kind of errors are really annoying me since I don't get any >> notification so often I am searching in the wrong places. >> >> Errorfun is just an empty module in this example. >> >> Thijs >> >> >> var assert = require('assert'); >> var errorfun = require('./errortestmodule'); >> var step = require('step'); >> >> process.on('uncaughtException'**, function(err) { >> console.log("___________ UNCAUGHT _____________\n"); >> console.log(err.message); >> console.log(err.stack); >> }); >> >> process.on('exit', function () { >> console.log('About to exit.'); >> }); >> >> function callNonexistant(callback){ >> setTimeout(errorfun.**nonexitant, 1000); >> } >> >> function doSomethingAsync(callback){ >> step( >> function(){ >> callNonexistant(this); >> }, >> function(err){ >> if(err) return callback(err); >> callback(null); >> } >> ); >> } >> >> function myCallback(err, result){ >> if(err) throw err; >> console.log("Finished and happy"); >> } >> >> >> doSomethingAsync(myCallback); >> > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
