-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default log function hides errors from developers #282
Comments
From what I can tell, this behavior is on purpose. Errors are caught and then logged (with the expectation being that the client using strophe.js will handle logging) so that an error doesn't cause the app to crash, thereby dropping the XMPP session and losing functionality. That said, I think adding some rudimentary logging (i.e. console.warn and console.error) is probably a good idea, since this has confused many people (including myself) in the past. |
Apologies for verbose brain-dump... Here are two possible reasons the code might be how it is now:
The first concern could be mitigated by checking for the presence of The second could be mitigated by having different defaults for warning level and above. Perhaps just two functions that the user can override, instead of one? Or encourage them to override any of the 5 they want to. Anyway, I'm seriously thinking whether we should just re-throw (or never catch) errors from callback functions. Most developers would expect an error in that situation, and developer tools can sometimes help the developer if an error is thrown (e.g. by pausing the debugger, or by logging the stack-trace and allowing clicks to the source code, or even logging the error to a DB for next-day analysis). However, re-throwing the Error would be a change in behaviour - a breaking change - so it should really only be part of a major version increment. (There could well be apps in the wild which rely on this behaviour to prevent their node server from crashing!) I guess I've talked myself back to just logging again! Or make throwing the error opt-in behaviour. Either way, I think we should ensure that the stack (or at least the line number) is logged when an error occurs, to assist debugging. |
I'm quite happy with how logging is done in converse.js (which uses strophe.js): It uses console.error, console.debug etc. if those are available, otherwise it falls back to console.log. Two issues...
|
If a callback function throws an error (due to a typo, unexpected condition, or whatever) strophe will catch the error and then hide it from the developer! Nothing will be logged.
This is due to the default log function doing nothing.
It is rather surprising to discover that errors everywhere in my code will throw, except errors inside callbacks passed to Strophe, which will fail silently.
My first thought is for default behaviour that leaves
log
,debug
andinfo
silent, but makeswarn
,error
andfatal
log the message, usingconsole.warn()
.If that is not possible, my alternative suggestion is that
fatal
should throw an error. This will at least expose the most heinous cases (such as the errors in callbacks described above).The text was updated successfully, but these errors were encountered: