jenkins-bot has submitted this change and it was merged.
Change subject: Improved API error reporting for ease of debugging
......................................................................
Improved API error reporting for ease of debugging
* We were not properly reporting mediawiki API errors in many
places. Instead, we were logging generic opaque error messages
that don't help with debugging the logged errors.
Change-Id: Ide384c75ba7f253a6b1e08a4451b8468c515b3e8
---
M lib/mediawiki.ApiRequest.js
1 file changed, 24 insertions(+), 12 deletions(-)
Approvals:
Arlolra: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/mediawiki.ApiRequest.js b/lib/mediawiki.ApiRequest.js
index ddeb0d7..49820e1 100644
--- a/lib/mediawiki.ApiRequest.js
+++ b/lib/mediawiki.ApiRequest.js
@@ -261,6 +261,20 @@
/**
* @method
* @private
+ * @param {Object} data API response body
+ * @param {string} requestStr request string -- useful to help debug what went
wrong
+ * @param {string} defaultMsg default error message if there were no
data.error property
+ */
+ApiRequest.prototype._errorObj = function(data, requestStr, defaultMsg) {
+ return new Error('API response Error for ' +
+ this.constructor.name + ': request=' +
+ (requestStr || '') + "; error=" +
+ JSON.stringify((data && data.error) || defaultMsg));
+};
+
+/**
+ * @method
+ * @private
* @param {Error|null} error
* @param {string} data wikitext / html / metadata
*/
@@ -435,7 +449,7 @@
logAPIWarnings(this, data);
if (!error && !data.query) {
- error = new Error("API response is missing query for: " +
this.title);
+ error = this._errorObj(data, '', 'Missing data.query');
}
if (error) {
@@ -574,8 +588,7 @@
logAPIWarnings(this, data);
if (!error && !(data && data.expandtemplates)) {
- error = new Error(util.format('Expanding template for %s: %s',
- this.title, this.text));
+ error = this._errorObj(data, this.text, 'Missing
data.expandtemplates.');
}
if (error) {
@@ -655,8 +668,7 @@
logAPIWarnings(this, data);
if (!error && !(data && data.parse)) {
- error = new Error(util.format('Parsing extension for %s: %s',
- this.title, this.text));
+ error = this._errorObj(data, this.text, 'Missing data.parse.');
}
if (error) {
@@ -684,11 +696,12 @@
this.batchParams = batchParams;
this.reqType = 'Batch request';
+ this.batchText = JSON.stringify(batchParams);
var apiargs = {
format: 'json',
formatversion: '2',
action: 'parsoid-batch',
- batch: JSON.stringify(batchParams),
+ batch: this.batchText,
};
this.requestOptions = {
@@ -717,7 +730,7 @@
BatchRequest.prototype._handleJSON = function(error, data) {
if (!error && !(data && data['parsoid-batch'] &&
Array.isArray(data['parsoid-batch']))) {
- error = new Error('Invalid result when expanding template
batch');
+ error = this._errorObj(data, this.batchText, 'Missing/invalid
data.parsoid-batch');
}
if (error) {
@@ -901,12 +914,11 @@
if (data.error.code === 'readapidenied') {
error = new AccessDeniedError();
} else {
- error = new Error('Something happened on the
API side. Message: ' +
- data.error.code + ': ' +
data.error.info);
+ error = this._errorObj(data);
}
} else {
- error = new Error("Config request returned no
result.\n" +
- JSON.stringify(data, "\t", 2));
+ error = this._errorObj(data, '',
+ 'No result.\n' + JSON.stringify(data, '\t', 2));
error.stack = null;
}
}
@@ -1021,7 +1033,7 @@
if (data.error.code === 'readapidenied') {
error = new AccessDeniedError();
} else {
- error = new Error('Something happened on the API side.
Message: ' + data.error.code + ': ' + data.error.info);
+ error = this._errorObj(data);
}
this._processListeners(error, {});
} else {
--
To view, visit https://gerrit.wikimedia.org/r/235402
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide384c75ba7f253a6b1e08a4451b8468c515b3e8
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits