[0.11.0 Regression] Edits fail but claim success (err = null)
Closed this issue · 3 comments
In most cases, such as http-level errors, json-parse errors, or standard MediaWiki API errors that use data.error = { code, info }
, nodemw detects it at the call()
layer in doRequest
, and will invoke the callback with just an Error object.
For doEdit(), this isn't the case for legacy behaviour where action=edit responds without data.error
but still have data.edit.result = "Failure"
. This is still the case for errors from AbuseFilter, ConfirmEdit, SpamBlacklist, and possibly others.
In those cases, additional information is in the other properties of the data.edit
object. Their format is non-standard, so we probably still can't provide anything beyond "Edit failed". However, I liked it before #121 because previously it would pass an Error object saying "Edit failed null". With 0.11.0 I'm just getting null, which means my callbacks assume success!
-
https://github.com/macbre/nodemw/blob/devel/lib/api.js#L209-L215
call()/doRequest()
sees the request as non-error because there is nodata.error
value. -
https://github.com/macbre/nodemw/blob/devel/lib/bot.js#L515-L522
if (!err && data.result && data.result === "Success") { callback(null, data); } else { callback(err); }
In
doEdit()
it then checks!err && data.result === "Success"
which fails given result is Failure, at which point it invoked the callback witherr
, which is null becausecall()
did not find any error.
The following would fix the regression, and also fulfil my request of wanting access to response data - which I assumed #121 would do:
- callback(err);
+ callback(err || data);
Ok, let's test it by adding http://clicky.pk/foo
to my personal sandbox user page (this triggers spam blacklist protection).