Error handling in modules

Author Message

Benjamin Seibert

Tuesday 22 March 2011 6:36:57 am

Hi there,

I'am currently trying to sort out a good way to handle errors in ezPublish modules. In the past we always have been using the default kernel errors.

 return $module->handleError(eZError::KERNEL_ACCESS_DENIED,'kernel');

In Most cases this method is just fine, especially because it produces no configuration overhead. Some time ago I have discovered the error.ini mechanism to generate custom errors. The mechanism to define custom errors seems to follow the traditional ez way (much configuration and glue).

To be able to signal one custom error, i have taken the following steps:

  1. Define [Error-<name>] section in the error.ini
  2. Create an interface containing the error codes as symbolic constants
  3. Create an error template in the subdirectory of the newly defined errortype

So far this is pretty streight foreward but a major drawback is the difference between symbolic PHP error constants and numeric ini values. Because INI files do not know about PHP constants, I cannot use them in the error.ini and thus have to use the numeric values that prior where hidden behind class constants. Because of this flaw the advantage of using constants instead of magical numbers is lost. If a want to change the magic number representing a custom error, i have to look through all ini files and change the magic numbers there as well. Also one always has to switch between the INI file and the error code definition to figure out the meaning of an error code. This is pretty bad for maintainability, especialy if you work on a large project that involves many developers.

Also there is an inconsistency in the handleError method of ezModule. As first Argument we use a class constant defined in ezError. The name of the class constant is due to the KERNEL_ prefix restricted to the kernel extension. The second parameter is passed as string.

Due to the above described problems, i came up with the following solution. Why not abandon the class constants and use human readable identifiers in both PHP and INI files.

[ErrorSettings-gallery]
# use symbolic names instead of numbers
HTTPError[to-large-to-copy]=502
ErrorHandler[to-large-to-copy]=embed
EmbedURL[to-large-to-copy]=user/login
 <?php
  // do stuff
  if(ERROR_CONDITION)
    return $module->handleError('to-large-to-copy','gallery');

This approach breaks the ez convention of defining error codes as numbers but the kernel/error module seems to handle this pretty well. After the above code, the template "error/gallery/to-large-to-copy.tpl" will be included and output a helpful context aware error message.

What do you thing of this approach? Are there any concerns regarding compatibility or general programming style?

thanx for you opinion,

ben

Robin Muilwijk

Wednesday 23 March 2011 1:59:06 am

Hi Ben,

I'm no code expert myself so can't give an opinion on your suggested solution/improvement, but I've sent a heads up to Engineering about it.

Regards Robin

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Bertrand Dunogier

Wednesday 23 March 2011 6:54:10 am

Engineering here.

I like your remarks, they make quite some sense. Even if it is built for this, the framework aspect of eZ Publish isn't as widely used as we could wish it was. We don't enough of that very accurate feedback, so first, thank you !

Error handling is imho one of our weaknesses, and I like what you're highlighting here. No promises can be made, but we are working on something quite big, and such feedback is clearly taken into consideration in this work. But since we are right in the middle of the final steps of the 4.5 release, I'll have to postpone further discussions about this topic until it is out.

Bertrand Dunogier
eZ Systems Engineering, Lyon
http://twitter.com/bdunogier
http://gplus.to/BertrandDunogier

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 10:16:27
Script start
Timing: Jan 18 2025 10:16:27
Module start 'layout'
Timing: Jan 18 2025 10:16:27
Module start 'content'
Timing: Jan 18 2025 10:16:29
Module end 'content'
Timing: Jan 18 2025 10:16:29
Script end

Main resources:

Total runtime1.0452 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 589.0469152.6250
Module start 'layout' 0.00530.0025 741.671939.4531
Module start 'content' 0.00781.0359 781.1250594.0547
Module end 'content' 1.04370.0015 1,375.179712.4766
Script end 1.0452  1,387.6563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2832160.0002
Check MTime0.00130.1201160.0001
Mysql Total
Database connection0.00100.098310.0010
Mysqli_queries0.983094.0484590.0167
Looping result0.00080.0764570.0000
Template Total1.007696.420.5038
Template load0.00180.173520.0009
Template processing1.005896.226820.5029
Template load and register function0.00020.018810.0002
states
state_id_array0.00100.092210.0010
state_identifier_array0.00110.103720.0005
Override
Cache load0.00160.1496310.0001
Sytem overhead
Fetch class attribute can translate value0.00060.054930.0002
Fetch class attribute name0.00130.120250.0003
XML
Image XML parsing0.00320.307330.0011
class_abstraction
Instantiating content class attribute0.00000.000950.0000
General
dbfile0.00490.4730240.0002
String conversion0.00000.000740.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/li.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/li.tplEdit templateOverride template
1content/datatype/view/ezxmltags/ol.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/ol.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs