I have started writing a plugin, and was wondering how any errors occurring in the plugin should be handled. Ideally, any errors occurring in the plugin should not bubble up to the user nor halt the script. But how do you communicate the error 1) to the user 2) to the developer? Is there a standard for this in Serendipity?
For example, my plugin makes a HTTP request using HTTP_Request. If this fails, the plugin can't render its content properly. I currently display a user-safe textual message like "No entries available" and write an error log with a corresponding error code and any useful additional info for debugging purposes.
I could not really find any hints regarding this otherwise...?
Error handling
-
TheArgh
- Regular
- Posts: 6
- Joined: Wed Mar 29, 2006 1:33 pm
- Location: Second planet from that big fiery ball
- Contact:
Error handling
Anthéa, 5800-pixel wide extravaganza (fr) - and the Almighty Argh!
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Re: Error handling
Hi!
Actually, there is very little standard upon error handling. Like any good PHP application, most plugins just swallow it or die ungraciously...
Anyways, wanting to do that is a good thing. Here's some suggestions:
1. You can make your plugin create a logfile or log errors to a database. Then you can use the backend_frontpage_display event hook to display those errors in the overview panel.
2. Or you can emit problems inside the plugin configuration screen. There use the "example" method that is called from your plugin to indicate any plugin code.
3. You could also send a mail to the user telling him errors.
4. Or, what would be terribly exiting is to use the external_plugin hook to create a RSS feed that holds error reports!
Then again, I'm also very open to any suggestions!
Best regards,
Garvin
Actually, there is very little standard upon error handling. Like any good PHP application, most plugins just swallow it or die ungraciously...
Anyways, wanting to do that is a good thing. Here's some suggestions:
1. You can make your plugin create a logfile or log errors to a database. Then you can use the backend_frontpage_display event hook to display those errors in the overview panel.
2. Or you can emit problems inside the plugin configuration screen. There use the "example" method that is called from your plugin to indicate any plugin code.
3. You could also send a mail to the user telling him errors.
4. Or, what would be terribly exiting is to use the external_plugin hook to create a RSS feed that holds error reports!
Then again, I'm also very open to any suggestions!
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
TheArgh
- Regular
- Posts: 6
- Joined: Wed Mar 29, 2006 1:33 pm
- Location: Second planet from that big fiery ball
- Contact:
Hi Garvin,
Thanks for the info! Items 1, 2 and 3 seem to be good solutions that one can choose depending on the type of error. I think plugin configuration issues can be checked via the example() method while functional errors can be mailed/displayed...
Otherwise, I don't like swallowing errors ungraciously - they have a tendency to get stuck in my throat
Regarding #4, that would indeed be nice - especially since this would require unifying error handling somewhat and adding an API for that
Ideally, the user should be able to choose in the serendipity configuration how he would like to be notified of errors: via an RSS feed, emails, logs... etc.
Yay! Ideas... isn't that what makes programming fun?
Thanks for the info! Items 1, 2 and 3 seem to be good solutions that one can choose depending on the type of error. I think plugin configuration issues can be checked via the example() method while functional errors can be mailed/displayed...
Otherwise, I don't like swallowing errors ungraciously - they have a tendency to get stuck in my throat
Regarding #4, that would indeed be nice - especially since this would require unifying error handling somewhat and adding an API for that
Yay! Ideas... isn't that what makes programming fun?
Anthéa, 5800-pixel wide extravaganza (fr) - and the Almighty Argh!
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi!
Great - actually 1.0 should also have a validate() method that can check configuration errors. Any errors found then should be displayed natively in the interface...
))
Of course current code would also need to be swamped with such hooks, which isn't but but just a lot of grunt work.
Sounds exciting, actually.
Best regards,
Garvin
Great - actually 1.0 should also have a validate() method that can check configuration errors. Any errors found then should be displayed natively in the interface...
Sssh. If you don't think about that and just close your eyes, all is fine! That way the ostrich seems to survive pretty well in natureOtherwise, I don't like swallowing errors ungraciously - they have a tendency to get stuck in my throat![]()
You are right, this really sounds pretty nifty. Actually it could be made with a plugin and a new "logger_error" hook. Plugins could call this, and could implement their own logger_error event handles, if they care. Plus, a super-plugin could handle all logger_error events (on top of local logging) to offer such RSSfeeds/mails/logfiles.Regarding #4, that would indeed be nice - especially since this would require unifying error handling somewhat and adding an API for thatIdeally, the user should be able to choose in the serendipity configuration how he would like to be notified of errors: via an RSS feed, emails, logs... etc.
Of course current code would also need to be swamped with such hooks, which isn't but but just a lot of grunt work.
Sounds exciting, actually.
Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
TheArgh
- Regular
- Posts: 6
- Joined: Wed Mar 29, 2006 1:33 pm
- Location: Second planet from that big fiery ball
- Contact:
That's good news! I'll have a look at the beta then and see if I can use that in my pluginGreat - actually 1.0 should also have a validate() method that can check configuration errors. Any errors found then should be displayed natively in the interface...
That would be perfect, as it would be easy to use and unify the error handling at the same time, which can never be a bad thing! And you don't have to worry about the way the errors are handled in your plugin...You are right, this really sounds pretty nifty. Actually it could be made with a plugin and a new "logger_error" hook. Plugins could call this, and could implement their own logger_error event handles, if they care. Plus, a super-plugin could handle all logger_error events (on top of local logging) to offer such RSSfeeds/mails/logfiles.
I would suggest a plugin-specific helper method that creates the hook for you so you only have to care about providing the error details likeOf course current code would also need to be swamped with such hooks, which isn't but but just a lot of grunt work.
Code: Select all
$this->logError( 4, 'Aaargh! An error is stuck in my throat!' );Anthéa, 5800-pixel wide extravaganza (fr) - and the Almighty Argh!
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
That all sounds good! Now the final question, who's going to volunteer? 
Error Handling and Documentation is for nerds only
) <gd&r>
Regards,
Garvin
Error Handling and Documentation is for nerds only
Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/