2016-07-20 15:45:04 +02:00
|
|
|
'use strict';
|
2014-02-15 20:57:38 +00:00
|
|
|
|
2014-09-12 23:04:35 +01:00
|
|
|
/**
|
|
|
|
|
* @dgProcessor errorDocsProcessor
|
|
|
|
|
* @description
|
|
|
|
|
* Process "error" docType docs and generate errorNamespace docs
|
|
|
|
|
*/
|
2017-03-22 11:09:40 +01:00
|
|
|
module.exports = function errorDocsProcessor(log, errorNamespaceMap, getMinerrInfo) {
|
2014-09-12 23:04:35 +01:00
|
|
|
return {
|
|
|
|
|
$runAfter: ['tags-extracted'],
|
|
|
|
|
$runBefore: ['extra-docs-added'],
|
|
|
|
|
$process: function(docs) {
|
|
|
|
|
|
2017-03-22 11:09:40 +01:00
|
|
|
// Get the extracted min errors to compare with the error docs, and report any mismatch
|
|
|
|
|
var collectedErrors = require('../../../build/errors.json').errors;
|
|
|
|
|
var flatErrors = [];
|
|
|
|
|
|
|
|
|
|
for (var namespace in collectedErrors) {
|
|
|
|
|
for (var error in collectedErrors[namespace]) {
|
|
|
|
|
flatErrors.push(namespace + ':' + error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-12 23:04:35 +01:00
|
|
|
// Create error namespace docs and attach error docs to each
|
|
|
|
|
docs.forEach(function(doc) {
|
|
|
|
|
var parts, namespaceDoc;
|
|
|
|
|
|
2016-07-20 15:45:04 +02:00
|
|
|
if (doc.docType === 'error') {
|
2014-09-12 23:04:35 +01:00
|
|
|
|
2017-03-22 11:09:40 +01:00
|
|
|
var matchingMinErr = flatErrors.indexOf(doc.name);
|
|
|
|
|
|
|
|
|
|
if (matchingMinErr === -1) {
|
|
|
|
|
log.warn('Error doc: ' + doc.name + ' has no matching min error');
|
|
|
|
|
} else {
|
|
|
|
|
flatErrors.splice(matchingMinErr, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-12 23:04:35 +01:00
|
|
|
// Parse out the error info from the id
|
|
|
|
|
parts = doc.name.split(':');
|
|
|
|
|
doc.namespace = parts[0];
|
|
|
|
|
doc.name = parts[1];
|
|
|
|
|
|
|
|
|
|
// Get or create the relevant errorNamespace doc
|
|
|
|
|
namespaceDoc = errorNamespaceMap.get(doc.namespace);
|
2016-07-20 15:45:04 +02:00
|
|
|
if (!namespaceDoc) {
|
2014-09-12 23:04:35 +01:00
|
|
|
namespaceDoc = {
|
|
|
|
|
area: 'error',
|
|
|
|
|
name: doc.namespace,
|
|
|
|
|
errors: [],
|
|
|
|
|
docType: 'errorNamespace'
|
|
|
|
|
};
|
|
|
|
|
errorNamespaceMap.set(doc.namespace, namespaceDoc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Link this error doc to its namespace doc
|
|
|
|
|
namespaceDoc.errors.push(doc);
|
|
|
|
|
doc.namespaceDoc = namespaceDoc;
|
|
|
|
|
doc.formattedErrorMessage = getMinerrInfo().errors[doc.namespace][doc.name];
|
2014-02-15 20:57:38 +00:00
|
|
|
}
|
2014-09-12 23:04:35 +01:00
|
|
|
});
|
|
|
|
|
|
2017-03-22 11:09:40 +01:00
|
|
|
flatErrors.forEach(function(value) {
|
|
|
|
|
log.warn('No error doc exists for min error: ' + value);
|
|
|
|
|
});
|
|
|
|
|
|
2014-09-12 23:04:35 +01:00
|
|
|
errorNamespaceMap.forEach(function(errorNamespace) {
|
|
|
|
|
docs.push(errorNamespace);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-07-20 15:45:04 +02:00
|
|
|
};
|