Skip Menu |

This queue is for tickets about the MediaWiki-API CPAN distribution.

Report information
The Basics
Id: 66388
Status: rejected
Priority: 0/
Queue: MediaWiki-API

People
Owner: Nobody in particular
Requestors: dan.bolser [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.35
Fixed in: (no value)



Subject: Error code is not 'reset' after a successful operation
I'm using an API object instance to process several pages in a loop. I have code to check for an error and exit the loop with a warning before going on to the next iteration, however, I found that after one such error, all subsequent operations were apparently failing. This was due to the fact that once the first operation failed, the error code got set correctly (which is how I tested for the error and quit the loop). However, after successfully completing the next operation in the next iteration, the error code was still set, causing my loop to crap out at the first step on all subsequent iterations, even though the operation was being completed successfully. I fixed the problem by manually resetting the error code after a failure, however, it would be nice if this happened automatically internally after a success.
Show quoted text
> I fixed the problem by manually resetting the error code after a > failure, however, it would be nice if this happened automatically > internally after a success.
Are you not checking if a function gives a correct return value? you shouldnt just read the error code unless there has been an error. It may be useful not to wipe the error code, as it could be thought of as "the last error". checking return codes is the way to do it. unless ive misunderstood you ?
From: dan.bolser [...] gmail.com
On Tue Mar 15 21:30:05 2011, exobuzz wrote: Show quoted text
> > I fixed the problem by manually resetting the error code after a > > failure, however, it would be nice if this happened automatically > > internally after a success.
> > Are you not checking if a function gives a correct return value? you > shouldnt just read the error code unless there has been an error. It may > be useful not to wipe the error code, as it could be thought of as "the > last error". checking return codes is the way to do it. unless ive > misunderstood you ?
I think I mis-understood how to use the 'on_error' function (thought it removed the need to explicitly catch errors). Indeed, I'm doing something very dumb here. I'll rewrite code to check return codes of all API object functions. Cheers,
Show quoted text
> I think I mis-understood how to use the 'on_error' function (thought it > removed the need to explicitly catch errors). Indeed, I'm doing > something very dumb here. > > I'll rewrite code to check return codes of all API object functions.
you can use on_error to trap errors and then fail for example or do something else - on error will only ever be called if something did produce an error and in that case the error message will be set. if you want to ignore the error and pretend it never happened, then you could for example clear the error code in that function, but in that case you still need to check if it returned something undefined for example. Perhaps it could be useful to clear the error code on success, but I don't see how this should cause a problem currently.
From: dan.bolser [...] gmail.com
On Wed Mar 16 15:23:18 2011, exobuzz wrote: snip Show quoted text
> Perhaps it could be useful to clear the error code on success, but I > don't see how this should cause a problem currently.
Indeed, current behaviour is fine now I understand it better. Cheers, Dan.