Jörn Zaefferer schrieb:
> Hi folks,
> 
> currently jQuery does not try to handle any programming errors by clients, 
> eg. an expression like "[EMAIL PROTECTED]", that is missing a closing bracket 
> "]", can result in quite confusing behaviour and is hard to spot. In other 
> places, like the problem described in bug #165 ( 
> http://jquery.com/dev/bugs/bug/165/ ), just catching the exception without 
> handling it is a very bad habit, but somewhat necessary to keep the code 
> small.
> 
> My idea is a small addition, that checks for the existence of a "logging" 
> object and uses that to log exceptions or potential errors. This addition 
> could be included by developers before jQuery and could help greatly when 
> developing and debugging. For production code, the remaining code would add 
> only a very small overhead. I'm not sure if this overhead should be removed, 
> eg. by the build script when packing the code. Or if it should be kept inside 
> the core to enable debugging a live site by including the additional script 
> before jQuery, without having to change the jQuery core code itself.
> 
> In the case of the problem described by Klaus, the logging could look like 
> this:
> 
> var modRes;
> try {
>     modRes = xml.getResponseHeader("Last-Modified");    
> } catch (e) {
>     ;;;if(typoeof $.log != "undefined") { $.log.error(e); }
> }
> if ( ifModified && modRes ) jQuery.lastModified[url] = modRes;
> 
> The three semicolons would allow the packed to remove the line...
> 
> Opinions are very welcome!
> 
> -- Jörn


I like that. I would love to have the log object use the FireBug console 
if present, otherwise log into some div like Stefan's solution.

Another thought (I wanted to implement that for a long time and maybe 
that would make a good plugin): What I want is to log any client-side 
errors via Ajax to the back-end log file as a QA action.

What do you think about that?

Like

$(window).error(function(e) {
     $.log(e); // not sure how to get the error out of here right now
});

and in try/catch blocks as well:

try {

} catch(e) {
     $.log(e);
}

That could even be combined by using a flag. If a variable for example 
called debug is set to true the errors are logged to the window/console, 
otherwise it logs to a server...

Of course it would need some additional back-end logic. Not sure if it 
is doable at all.


-- Klaus

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to