poll: howto do informative error handling without the fatalities
poll: howto do informative error handling without the fatalities
am 09.02.2010 06:42:22 von Rene Veerman
Hi,
I'm looking for a strategy to do informative error handling at all
levels of my code, yet keep these errors non-fatal as often as
possible.
Adhering to a proper code-standard with regards to error handling
would speed up development of any code (it would shorten the bug-hunt
time a lot), but it becomes especially usefull for code that processes
items in large diverse datasets; exceptions should be logged (in
different ways) but should not kill off the processing of other items.
I have some experience with set_error_handler() and trigger_error(),
but haven't perfected my use of them yet.
Take for instance the following function;
function chase ($arr, $indexes) {
$r = $arr;
foreach ($indexes as $idx) {
if (is_array($r)) {
$r = $r[$idx];
} else {
trigger_error (htmlDumpReturn (
array (
'arr' => $arr,
'indexes' => $indexes
), 'chase() could not walk the full tree.'
), E_USER_WARNING);
return false;
}
}
return $r;
}
This is a low-level function used by me to traverse to a value several
arbitrary levels into an array.
As you can see, things will be fine for any value that is not
(boolean)false, but if i'm ever to fetch a "false" value, things will
break.
The solution i can think of is to have all my functions return not
their results directly, but 1 of these arrays instead:
//good result:
return array (
'result' => $valueFound
);
//no result / bad result:
return array (
'error' => 'same error details as passed to trigger_error()'
);
While this would allow the calling code to fudge, redirect or omit the
failed-item, i have a small fear that this approach leads to
"complicated" code whenever a function is called, but I suppose that
with a few extra short-named functions ( like is_error() ) the calling
code can be kept short and simple too.
(local) log-levels and (also local) redirection-of-error-messages i
can solve with global variables and some functions to manipulate
those.
My question to you all is; do you know a simpler way of achieving what
i'm aiming for?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: poll: howto do informative error handling without the fatalities
am 09.02.2010 07:22:05 von Rene Veerman
I would also like to hear suggestions on how to fix this mess:
$r = funcA ( funcB ( funcC ( $p ) ) );
if funcB() / funcC() fails, how would you fudge/abort the calling
function in the chain?
One may think that funcA and funcB just check their parameters list
for being "error" arrays, but the problem i foresee is that depending
on the context of the $r= call, desired behaviour may vary at any
stage in the funcA -> funcB -> funcC chain.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling withoutthe fatalities
am 09.02.2010 07:35:03 von Teus Benschop
On Tue, 2010-02-09 at 07:22 +0100, Rene Veerman wrote:
> I would also like to hear suggestions on how to fix this mess:
>=20
> $r =3D funcA ( funcB ( funcC ( $p ) ) );
>=20
> if funcB() / funcC() fails, how would you fudge/abort the calling
> function in the chain?
> One may think that funcA and funcB just check their parameters list
> for being "error" arrays, but the problem i foresee is that depending
> on the context of the $r=3D call, desired behaviour may vary at any
> stage in the funcA -> funcB -> funcC chain.
>=20
I would abort it by embedding the mess in a try.. catch statement, then
throwing an exception. Teus.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: poll: howto do informative error handling without the fatalities
am 09.02.2010 12:48:20 von Nathan Rixham
Rene Veerman wrote:
> Hi,
>
> I'm looking for a strategy to do informative error handling at all
> levels of my code, yet keep these errors non-fatal as often as
> possible.
error_log - for logging errors
throw Exception - for show stoppers
try/catch - for when you can handle a potential show stopper
custom error logging / messaging can easily be achieved with something
like this:
class Messenger
{
private static $_messages = array();
public static function addMessage( $string )
{
self::$_messages[] = $string;
if( $string instanceof Exception ) {
echo self::report();
}
}
public static function report()
{
return implode( PHP_EOL , self::$_messages );
}
}
set_exception_handler( 'Messenger::addMessage' );
Messenger::addMessage( 'little error report 1' );
Messenger::addMessage( 'little error report 2' );
Messenger::addMessage( 'little error report 3' );
throw new Exception( 'this will stop the script' );
// exception will kill the script; if you comment it out
// or wrap it in a try catch then you can keep going..
Messenger::addMessage( 'little error report 4' );
// try catch exceptions and report them like this..
try {
throw new Exception( 'we could catch this' );
} catch ( Exception $e ) {
Messenger::addMessage( $e );
}
Messenger::addMessage( 'little error report 5' );
// and when your done just echo it out or save it or..
echo Messenger::report();
Regards!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 13:01:25 von Richard Quadling
On 9 February 2010 11:48, Nathan Rixham wrote:
> Rene Veerman wrote:
>> Hi,
>>
>> I'm looking for a strategy to do informative error handling at all
>> levels of my code, yet keep these errors non-fatal as often as
>> possible.
>
> error_log - for logging errors
> throw Exception - for show stoppers
> try/catch - for when you can handle a potential show stopper
>
> custom error logging / messaging can easily be achieved with something
> like this:
>
>
>
> class Messenger
> {
>
> Â private static $_messages =3D array();
>
> Â public static function addMessage( $string )
> Â {
> Â Â self::$_messages[] =3D $string;
> Â Â if( $string instanceof Exception ) {
> Â Â Â echo self::report();
> Â Â }
> Â }
>
> Â public static function report()
> Â {
> Â Â return implode( PHP_EOL , self::$_messages );
> Â }
>
> }
>
> set_exception_handler( 'Messenger::addMessage' );
>
> Messenger::addMessage( 'little error report 1' );
> Messenger::addMessage( 'little error report 2' );
> Messenger::addMessage( 'little error report 3' );
> throw new Exception( 'this will stop the script' );
> // exception will kill the script; if you comment it out
> // or wrap it in a try catch then you can keep going..
> Messenger::addMessage( 'little error report 4' );
> // try catch exceptions and report them like this..
> try {
> Â throw new Exception( 'we could catch this' );
> } catch ( Exception $e ) {
> Â Messenger::addMessage( $e );
> }
> Messenger::addMessage( 'little error report 5' );
> // and when your done just echo it out or save it or..
> echo Messenger::report();
>
>
> Regards!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
I have extended the standard exception class to send me an email
whenever an exception occurs.
I treat all errors on the live system as exceptions. They shouldn't
occur. If they do, I've missed something.
But at least I'll get a near instant notification of the issue, along
with the stack and all the params involved.
Very useful.
--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 13:55:59 von Richard
Hi,
> I have extended the standard exception class to send me an email
> whenever an exception occurs.
I did that once. Once being the operative word... :-) Ended up with
tens of thousands of emails one morning. At first I thought... "Wow,
maybe my popularity has grown somewhat". But it hadn't.
--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 31st January)
Lots of PHP and Javascript code - http://www.phpguru.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 14:00:57 von Richard Quadling
On 9 February 2010 12:55, Richard wrote:
> Hi,
>
>> I have extended the standard exception class to send me an email
>> whenever an exception occurs.
>
> I did that once. Once being the operative word... :-) Ended up with
> tens of thousands of emails one morning. At first I thought... "Wow,
> maybe my popularity has grown somewhat". But it hadn't.
>
> --
> Richard Heyes
> HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 31st January)
> Lots of PHP and Javascript code - http://www.phpguru.org
>
But I bet you REALLY quickly fixed the problem!
Oh. BTW. Thanks for RMail (previously known as htmlmimemail5 if anyone
else is interested).
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 14:44:07 von Richard
Hi,
> But I bet you REALLY quickly fixed the problem!
I just took out the error handling. :-)
--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 7th February)
Lots of PHP and Javascript code - http://www.phpguru.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the fatalities
am 09.02.2010 15:19:57 von Robert Cummings
Richard wrote:
> Hi,
>
>> I have extended the standard exception class to send me an email
>> whenever an exception occurs.
>
> I did that once. Once being the operative word... :-) Ended up with
> tens of thousands of emails one morning. At first I thought... "Wow,
> maybe my popularity has grown somewhat". But it hadn't.
I have something similar... a cron job that checks the error_log file
every 10 minutes and sends me the contents if any exist. I also set a
special header so I can be sure it's not spam and appropriately route it
into my mail folder maze, Much less spammy :)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling withoutthe fatalities
am 09.02.2010 15:20:34 von Ashley Sheridan
--=-cG3Y1TeDC9xeoNYSvn6d
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
> Richard wrote:
> > Hi,
> >
> >> I have extended the standard exception class to send me an email
> >> whenever an exception occurs.
> >
> > I did that once. Once being the operative word... :-) Ended up with
> > tens of thousands of emails one morning. At first I thought... "Wow,
> > maybe my popularity has grown somewhat". But it hadn't.
>
> I have something similar... a cron job that checks the error_log file
> every 10 minutes and sends me the contents if any exist. I also set a
> special header so I can be sure it's not spam and appropriately route it
> into my mail folder maze, Much less spammy :)
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
Real developers don't have errors in their code; they're undocumented
features ;)
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-cG3Y1TeDC9xeoNYSvn6d--
Re: Re: poll: howto do informative error handling without thefatalities
am 09.02.2010 15:55:58 von Robert Cummings
Ashley Sheridan wrote:
> On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
>
>> Richard wrote:
>>> Hi,
>>>
>>>> I have extended the standard exception class to send me an email
>>>> whenever an exception occurs.
>>> I did that once. Once being the operative word... :-) Ended up with
>>> tens of thousands of emails one morning. At first I thought... "Wow,
>>> maybe my popularity has grown somewhat". But it hadn't.
>> I have something similar... a cron job that checks the error_log file
>> every 10 minutes and sends me the contents if any exist. I also set a
>> special header so I can be sure it's not spam and appropriately route it
>> into my mail folder maze, Much less spammy :)
>>
>> Cheers,
>> Rob.
>> --
>> http://www.interjinn.com
>> Application and Templating Framework for PHP
>>
>
>
> Real developers don't have errors in their code; they're undocumented
> features ;)
Hmmmm... I've always gone with "a wise man learns from his mistakes".
Not that I'm saying I'm wise or anything... just seems a good goal to
shoot for :)
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 17:09:05 von Richard Quadling
On 9 February 2010 14:20, Ashley Sheridan wrote:
>
> On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
>
> Richard wrote:
> > Hi,
> >
> >> I have extended the standard exception class to send me an email
> >> whenever an exception occurs.
> >
> > I did that once. Once being the operative word... :-) Ended up with
> > tens of thousands of emails one morning. At first I thought... "Wow,
> > maybe my popularity has grown somewhat". But it hadn't.
>
> I have something similar... a cron job that checks the error_log file
> every 10 minutes and sends me the contents if any exist. I also set a
> special header so I can be sure it's not spam and appropriately route it
> into my mail folder maze, Much less spammy :)
>
> Cheers,
> Rob.
> --
> http://www.interjinn.com
> Application and Templating Framework for PHP
>
>
> Real developers don't have errors in their code; they're undocumented features ;)
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
So, no documentation AND bugs!!! Gee. I really wouldn't want to rely
on that code base!
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 17:13:33 von Richard
Hi,
>> Real developers don't have errors in their code; they're undocumented features ;)
Or alternatively, if you freelance - "Forthcoming employment opportunities" :-)
--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 7th February)
Lots of PHP and Javascript code - http://www.phpguru.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the fatalities
am 09.02.2010 23:25:35 von Clancy
On Tue, 9 Feb 2010 16:09:05 +0000, rquadling@googlemail.com (Richard Quadling) wrote:
>On 9 February 2010 14:20, Ashley Sheridan wrote:
>>
>> On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
>>
>> Richard wrote:
>> > Hi,
>> >
>> >> I have extended the standard exception class to send me an email
>> >> whenever an exception occurs.
>> >
>> > I did that once. Once being the operative word... :-) Ended up with
>> > tens of thousands of emails one morning. At first I thought... "Wow,
>> > maybe my popularity has grown somewhat". But it hadn't.
>>
>> I have something similar... a cron job that checks the error_log file
>> every 10 minutes and sends me the contents if any exist. I also set a
>> special header so I can be sure it's not spam and appropriately route it
>> into my mail folder maze, Much less spammy :)
>>
>> Cheers,
>> Rob.
>> --
>> http://www.interjinn.com
>> Application and Templating Framework for PHP
>>
>>
>> Real developers don't have errors in their code; they're undocumented features ;)
>>
>> Thanks,
>> Ash
>> http://www.ashleysheridan.co.uk
>>
>>
>
>So, no documentation AND bugs!!! Gee. I really wouldn't want to rely
>on that code base!
So you don't use (or work with) any Microsoft product?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 09.02.2010 23:38:42 von Rene Veerman
Well, i've thought of a few ways to allow localized overriding of
values returned by functions in case of an error.
I have yet to figure out what the exact advantages are of this
code-standard, but the overhead seems acceptable and i recon this,
when done, will beat the "trigger_error()-try-catch" paradigm.
I'd like to hear your comments.
// imo unsafe & prone to fatalities:
$r = funcA ( funcB ( funcC ($p) ), funcD ($q) );
// "safe"; make all notices, warnings and errors from any level
// in the call-chain fully visible, identifiable, and "survivable/fudgeable"
// by code at (all) higher levels in the call-chain.
// [disclaimer] the code below here doesn't pass 3rd-level (funcC())
// (meta-)results back to the first level (funcA()) yet, but this code
// is a start towards that;
$r = funcA (defaults(array(0=>'[funcB failed]',1=>'funcD failed'))),
funcB (defaults($onError_cCallvalue),
funcC (defaults($onError_pValue), $p)
),
funcD (defaults($onError_qValue), $q)
);
function funcA ($defaults, $returnedByFuncB, $returnedByFuncD) {
$returnedByFuncB = workWith ($defaults, $returnedByFuncB, 0);
$returnedByFuncD = workWith ($defaults, $returnedByFuncD, 1);
//all parameters (with idx>0) are meta-arrays containing the
"parameter-value" and all meta-info.
// workWith() always returns the actual parameter-value in $p['workValue'];
//if any parameter $p (with idx>0) is not a meta-array,
// workWith($d, $r, $n) turns it into a meta array(
// 'workValue' => $p
// );
//if a param is a meta-array $p, and it contains an ['errors'] subarray,
// workWith() sets by-reference $p['workValue'] to one of these
(order of trying):
// $defaults['onError'][$n] (localized override)
// $p['onErrorDefault'], (functions own default value for when an
error occurs)
//first call to workWith(,,0) will call beginErrorContext()
//beginErrorContext() will increase a global idx $callID (int),
// used to list all notices, warnings and errors, and their details in
// the global variable $callsErrors[$callID][$errorIdx++] = array(
// 'errorMsg' => 'for coders'
// (optional:)'userErrorMsg' => 'for laymen'
// 'backtrace' => array(....)
// )
// the never-fatal error handler specified with set_error_handler() will
// call getDebugInfo() and append full error info into
// $callsErrors[$callID][$errorIdx++]
//forwardDefaults() clones all meta-details for
// re-used parameters into a new $defaults array to be used
// by funcE().
//the 2nd parameter for forwardDefaults lists which parameter
// passed deeper refers to which parameter received by this here function.
//the 3rd parameter for forwardDefaults is used to specify new defaults.
$returnedByFuncF = funcF('blablasetting');
$x = funcE (
forwardDefaults($defaults, array(0=>0,2=>1), array(1 => 'defaultblabla')),
$returnedByFuncB, $returnedByFuncF, $returnedByFuncD
);
return goodResult($x);
}
function funcE ($defaults, $returnedByFuncB, $returnedByFuncF,
$returnedByFuncD) {
$returnedByFuncB = workWith ($defaults, $returnedByFuncB, 0);
$returnedByFuncF = workWith ($defaults, $returnedByFuncF, 2);
$returnedByFuncD = workWith ($defaults, $returnedByFuncD, 2);
// do a call that might raise E_WARNINGS or other crap;
// safeCall() is only a try-except struct to call in this case
// str_replace('xx','yy', ...) and if it fails,
// return the default instead of the actual result.
$x = safeCall (
defaults('returnedByFuncB not a string'),
'str_replace', 'xx','yy',$returnedByFuncB
);
if (is_string($returnedByFuncB) && is_string($returnedByFuncD)) {
return goodResult (
$returnedByFuncB . $returnedByFuncD . $x
);
// goodResult() and badResult() will both call
// endErrorContext(), and copy the errors in
// $callsErrors[$callID]
// to the array returned to the calling function.
// goodResult() and badResult() will call processErrors(),
// which is repsonsible for mailing / db-storage of any
// notices, warnings, errors, etc.
} else {
// badResult() will call getDebugInfo() to include
// a full trace, superglobals, lotsa details.
return badResult (array(
'errorMsg' => 'params 1 and 2 must be strings'
'onErrorDefault' => ''
));
//shorthand of the above:
return badResult ('params 1 and 2 must be strings', '');
}
}
function defaults () {
$r = array (
'isMetaForFuncs' => true
);
if (func_num_args()==1) {
return array_merge_recursive ($r,
array('onError'=>array(0=>func_get_arg(0))));
} else {
switch (func_get_arg(0)) {
case 'onError':
$p = func_get_arg(1);
if (is_array($p)) {
return array_merge_recursive ($r, array('onError'=>$p));
} else {
return array_merge_recursive ($r, array('onError'=>array(0=>$p)));
}
break;
}
}
}
I also considered the following constructs but rejected them for
clumsiness (first) or sheer uselessness (2nd).
$r = funcA ($bcalldef, funcB($ccalldef, funcC ($pdef, $p)),
$dcalldef, funcD($qdef, $q));
$r = funcA ( funcB ( funcC ( $p ) ), funcD ($q), array (
'isMetaForFuncs' => true,
0 => array (
'onError' => $bCallDefaultOnError,
0 => array (
'onError' => $cCallDefaultOnError,
0 => array (
'onError' => $pDefaultOnError,
)
)
),
1 => array (
'onError' => $qDefaultOnError
)
);
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without
am 10.02.2010 03:04:35 von Paul M Foster
On Tue, Feb 09, 2010 at 11:38:42PM +0100, Rene Veerman wrote:
> Well, i've thought of a few ways to allow localized overriding of
> values returned by functions in case of an error.
>
> I have yet to figure out what the exact advantages are of this
> code-standard, but the overhead seems acceptable and i recon this,
> when done, will beat the "trigger_error()-try-catch" paradigm.
> I'd like to hear your comments.
>
> // imo unsafe & prone to fatalities:
> $r = funcA ( funcB ( funcC ($p) ), funcD ($q) );
I wasn't going to comment, but seriously, Rene, I would not make it a
habit of calling functions within the parameters of other functions.
Among other things, it obviously creates a whole host of the problems
you're talking about, and it makes your code hard to debug and read. The
only way I'd normally do something like this is if I were using native
PHP functions and the possible failure of the functions wouldn't matter.
Rather, I'd do something like this:
$d = funcD($q);
// tests if necessary
$c = funcC($p);
// tests if necessary
$b = funcB($c);
// tests if necessary
$r = funcA($b, $d);
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 10.02.2010 07:04:04 von Rene Veerman
On Wed, Feb 10, 2010 at 3:04 AM, Paul M Foster wrote:
> $d = funcD($q);
> // tests if necessary
> $c = funcC($p);
> // tests if necessary
> $b = funcB($c);
> // tests if necessary
> $r = funcA($b, $d);
>
You're right.
I knew when i was posting my last reply yesterday that i had made
things probably too complicated.
But after sleeping and a look at real code which is to work with my
improved-err-handling, i've come up with a new construct, that i think
will fit the bill for now.
I'm going to use the "result meta-array" instead of "plain result
values", because that
- completely equalizes the syntax for detecting bad results, and
prevents doing a lookup with a function to a value that is also the
"bad-result" return value for the lookup function.
- is much easier to read, than checking what the "bad-result" value is
for a lookup function.
- allows me to redirect the error info from a called function inside
the calling function
- allows infinite expansion of (meta-)communication between calling
and called functions.
So while i'm dumping the funcA (defaults($onError_pValue), $p) crap,
i'm retaining most of the other ideas in my previous post to this
thread.
the calling function does this, inside 3x foreach:
.........
// if not done yet, resolve the fields for this table=>hit that
require looking-up
if (!$sqls[$tableName]['hasPreInserts']) {
foreach ($tableCmd['preInsertFields'] as $fieldName=>$fieldLookupCmd) {
$r = maintenance__lookupPreInserts ($wm, $fieldLookupCmd);
if (!good($r)) {
$tableCmd['invalidPreInserts'] = true;
} else {
$sqls[$tableName]['preInserts'][$fieldName] = result($r);
}
}
}
if (!array_key_exists('invalidPreInserts', $tableCmd)) {
// add the fields for this table for this hit:
..........
and the helper functions:
function maintenance__lookupPreInserts (&$wm, $fieldLookupCmd) {
startErrorContext(); // to catch php E_NOTICE, E_WARNING, etc
$flcp = explode ('::', $fieldLookupCmd);
if (count($flcp)!=3) {
return badResult(E_USER_ERROR, array(
'msg' => 'Need 3 counts of \'::\'',
'vars' => array (0=>array('$fieldLookupCmd', $fieldLookupCmd))
));
}
$section = $flcp[0];
$searchInSection = array();
$criteria = explode (',,', $flcp[1]);
foreach ($criteria as $idx1 => $criterium) {
$cs = explode('===',$flcp[1]);
if (count($cs)!=2) return badResult (E_USER_ERROR, array(
'msg' =>
'Any criterium (after first "::", between ",,") needs to be like
this:'."\n".
'fieldName===searchValue',
'vars' => array (0=>array('$fieldLookupCmd', $fieldLookupCmd))
));
$searchInSection = array_merge ($searchInSection, array(
$cs[0] => $cs[1]
));
}
$pathInSection = explode(',,', $flcp[2]);
foreach ($wm[$section] as $idx => $fields) {
$gotIt = true;
foreach ($searchInSection as $fn => $fv) {
if ($fields[$fn]!=$fv) {
$gotIt = false;
break;
}
}
if ($gotIt) {
return chase ($wm[$section], $pathInSection);
}
}
}
function chase ($arr, $indexes) {
startErrorContext();
$r = $arr;
foreach ($indexes as $idx) {
if (is_array($r)) {
$r = $r[$idx];
} else {
return badResult (E_USER_ERROR, array(
'msg' => 'Could not walk the full tree',
'vars' => array(
0=>array('$arr', $arr),
1=>array('$indexes', $indexes)
)
));
}
}
return goodResult($r);
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: poll: howto do informative error handling without the
am 10.02.2010 12:57:41 von Richard Quadling
On 9 February 2010 22:25, wrote:
> On Tue, 9 Feb 2010 16:09:05 +0000, rquadling@googlemail.com (Richard Quadling) wrote:
>
>>On 9 February 2010 14:20, Ashley Sheridan wrote:
>>>
>>> On Tue, 2010-02-09 at 09:19 -0500, Robert Cummings wrote:
>>>
>>> Richard wrote:
>>> > Hi,
>>> >
>>> >> I have extended the standard exception class to send me an email
>>> >> whenever an exception occurs.
>>> >
>>> > I did that once. Once being the operative word... :-) Ended up with
>>> > tens of thousands of emails one morning. At first I thought... "Wow,
>>> > maybe my popularity has grown somewhat". But it hadn't.
>>>
>>> I have something similar... a cron job that checks the error_log file
>>> every 10 minutes and sends me the contents if any exist. I also set a
>>> special header so I can be sure it's not spam and appropriately route it
>>> into my mail folder maze, Much less spammy :)
>>>
>>> Cheers,
>>> Rob.
>>> --
>>> http://www.interjinn.com
>>> Application and Templating Framework for PHP
>>>
>>>
>>> Real developers don't have errors in their code; they're undocumented features ;)
>>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>
>>So, no documentation AND bugs!!! Gee. I really wouldn't want to rely
>>on that code base!
>
> So you don't use (or work with) any Microsoft product?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
The closest I get is MSSQL which has BOL (Books OnLine). Its enough.
Occasionally MS Excel VBA which is fairly well documented and always
accessible via a COM interface (so self documenting more or less).
But point taken.
And only 12 MS critical updates today! Woo Hoo!
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php