chore(doc-gen): report on missing or obsolete error docs

Closes #12527
This commit is contained in:
Martin Staffa
2017-03-22 11:09:40 +01:00
committed by Martin Staffa
parent b9d2b30808
commit 9de0842719
+23 -1
View File
@@ -5,18 +5,36 @@
* @description
* Process "error" docType docs and generate errorNamespace docs
*/
module.exports = function errorDocsProcessor(errorNamespaceMap, getMinerrInfo) {
module.exports = function errorDocsProcessor(log, errorNamespaceMap, getMinerrInfo) {
return {
$runAfter: ['tags-extracted'],
$runBefore: ['extra-docs-added'],
$process: function(docs) {
// 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);
}
}
// Create error namespace docs and attach error docs to each
docs.forEach(function(doc) {
var parts, namespaceDoc;
if (doc.docType === 'error') {
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);
}
// Parse out the error info from the id
parts = doc.name.split(':');
doc.namespace = parts[0];
@@ -41,6 +59,10 @@ module.exports = function errorDocsProcessor(errorNamespaceMap, getMinerrInfo) {
}
});
flatErrors.forEach(function(value) {
log.warn('No error doc exists for min error: ' + value);
});
errorNamespaceMap.forEach(function(errorNamespace) {
docs.push(errorNamespace);
});