|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Tue Nov 19, 2013 7:43 pm Post subject: Trapping runtime errors |
|
|
I'm aiming to have user-facing Smarty templates. This means I need to go heavy on security settings and error handling, and so far it's working well.
I'm trapping compile time errors nicely and that's working really well. More difficult is runtime errors, in particular undefined indexes, undefined variables. I have an error handler in my template class and that gets called when those errors occur, but the contextual info I receive isn't as good as what's available for compile-tme errors. In particular the line numbers don't relate to the template, but usually to the smarty_internal_templatebase class which throws the error. Is there any way I can squeeze some better, more accurate info out of these errors?
Alternatively, is there some way I can validate assigned variables against a compiled template before trying to run it? |
|
Back to top |
|
Synchro Smarty Regular
Joined: 27 Apr 2008 Posts: 43
|
Posted: Wed Nov 20, 2013 4:02 pm Post subject: |
|
|
I've not managed to get anything more out of Smarty, but I have managed to come up with a reasonably effective solution to this. I'm pre-parsing the template with the stack of assigned vars in hand, and looking for any instance of vars or array references that don't match what's in the assigned vars. This lets me trap bad vars and wrong indexes before smarty gets involved. With a bit of PREG_OFFSET_CAPTURE I'm also able to extract error line numbers and the code at fault.
I'm making it throw Smarty compiler exceptions so that they look the same as Smarty's own errors, which simplifies reporting and presentation quite a bit.
If it gets past that, it then goes on with a smarty trial compile and fetch where an extra error handler and exception catcher deals with the errors that smarty does detect nicely.
I'm sure there will be some edge cases it doesn't catch elegantly, but it covers the vast majority of likely errors. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Nov 20, 2013 7:18 pm Post subject: |
|
|
FYI Smarty 3.2 will trace back errors with template source line information.
But I have currently not yet a release date. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|