Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 6 and Version 7 of HowDoesErrorHandlingWork


Ignore:
Timestamp:
02/22/06 14:52:02 (9 years ago)
Author:
simon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • HowDoesErrorHandlingWork

    v6 v7  
    22 
    33'''WARNING: error handling is still in state of flux, the following page is primarily intended for developers.''' 
    4  
    5 '''WARNING2: for now, don't mix decorators and the syntax using tg_errors attribute.  It won't work, yet.  Even if in different modules in your system. -- SOLVED in r781''' 
    64 
    75= 1 Validation errors = 
     
    5149== 1.2 Dispatch rules == 
    5250 
    53 What if we want to handle invalid baz-es differently than invalid bar-s? Fortunately for us, ''error_handler'' takes a second (keyword) argument ''rules'', making it possible to influence selection of appropriate error handler (actually a limited interface to ''RuleDispatch''[1]). 
     51What if we want to handle invalid baz-es differently than invalid bar-s? Fortunately for us, ''error_handler'' takes a second keyword argument ''rules'', making it possible to influence selection of appropriate error handler (actually a limited interface to ''RuleDispatch''[1]). 
    5452Rules are arbitrary logical Python expressions passed as lists. For example: 
    5553{{{ 
     
    6563@error_handler(rules="'baz' in tg_errors") 
    6664}}} 
     65 
     66 
     67== 1.3 Fail-safe mechanism == 
     68 
     69If validation fails for an input, said input also does not get to be converted to designated Python type, which could be rather inconvenient. A fail-safe mechanism is provided for such cases. Decorator ''validate'' can take two additional keyword arguments ''failsafe_scheme'' and ''failsafe_values'' to fine-tune how to failed inputs are handled.  
     70 
     71Predefined schemes (in turbogears/errorhandling.py): 
     72 
     73* ''FailsafeSchema.none'': Default. No conversions are preformed, input remains as is: 
     74{{{ 
     75@validate(validators={...}) 
     76}}} 
     77or explicitly: 
     78{{{ 
     79@validate(validators={...}, failsafe_scheme=errorhandling.FailsafeSchema.none) 
     80}}} 
     81''failsafe_values'' is ignored. 
     82 
     83* ''FailsafeSchema.values'': If ''failsafe_values'' is a dict, every input for which exists a key in ''failsafe_values'' is replaced with corresponding value. Otherwise all erroneous inputs are replaced with (same instance of!) ''failsafe_values''. 
     84{{{ 
     85@validate(validators={"bar":validators.Int(), "baz":validators.Int()}, failsafe_schema=FailsafeSchema.values, failsafe_values={"bar":1, "baz":2}) 
     86}}} 
     87If erroneous, bar is set to (int) 1, while baz to 2. 
     88{{{ 
     89@validate(validators={"bar":validators.Int(), "baz":validators.Int()}, failsafe_schema=FailsafeSchema.values, failsafe_values=13) 
     90}}} 
     91Both bar and baz are set to 13 when erroneous. 
     92 
     93* ''FailsafeSchema.map_errors'': Inputs are mapped to corresponding exceptions.  
     94{{{ 
     95@validate(validators={"bar":validators.Int(), "baz":validators.Int()}, failsafe_schema=FailsafeSchema.map_errors) 
     96}}} 
     97''failsafe_values'' is ignored. 
     98 
     99User defined schemas can be added by defining new specialisations for generic function ''errorhandling.dispatch_failsafe''. 
     100 
    67101 
    68102= 2 Exceptions =