Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(doc-gen): add formatted error messages to error pages #6363

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/config/processors/error-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@ module.exports = {
runAfter: ['tags-extracted'],
init: function(config, injectables) {
injectables.value('errorNamespaces', {});

var minerrInfoPath = config.get('processing.errors.minerrInfoPath');
if ( !minerrInfoPath ) {
throw new Error('Error in configuration: Please provide a path to the minerr info file (errors.json) ' +
'in the `config.processing.errors.minerrInfoPath` property');
}
injectables.value('minerrInfo', require(minerrInfoPath));
},
process: function(docs, partialNames, errorNamespaces) {
process: function(docs, partialNames, errorNamespaces, minerrInfo) {

// Create error namespace docs and attach error docs to each
_.forEach(docs, function(doc) {
Expand All @@ -32,6 +39,8 @@ module.exports = {
namespaceDoc.errors.push(doc);
doc.namespace = namespaceDoc;

doc.formattedErrorMessage = minerrInfo.errors[doc.namespace.name][doc.name];

}

});
Expand Down
17 changes: 17 additions & 0 deletions docs/config/templates/error.template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "base.template.html" %}

{% block content %}
<h1>Error: {$ doc.id $}
<div><span class='hint'>{$ doc.fullName $}</span></div>
</h1>

<div>
<pre class="minerr-errmsg" error-display="{$ doc.formattedErrorMessage $}">{$ doc.formattedErrorMessage $}</pre>
</div>

<h2>Description</h2>
<div class="description">
{$ doc.description | marked $}
</div>

{% endblock %}
3 changes: 3 additions & 0 deletions docs/docs.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module.exports = function(config) {
});
config.set('processing.examples.dependencyPath', '../../..');


config.set('processing.errors.minerrInfoPath', path.resolve(basePath, '../build/errors.json'));

config.set('rendering.outputFolder', '../build/docs');

config.set('logging.level', 'info');
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/docsAppE2E.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,31 @@ describe('docs.angularjs.org', function () {
expect(code.getText()).toContain('guest!!!');
});


it('should be resilient to trailing slashes', function() {
browser.get('index-debug.html#!/api/ng/function/angular.noop/');
var pageBody = element(by.css('h1'));
expect(pageBody.getText()).toEqual('angular.noop');
});


it('should be resilient to trailing "index"', function() {
browser.get('index-debug.html#!/api/ng/function/angular.noop/index');
var pageBody = element(by.css('h1'));
expect(pageBody.getText()).toEqual('angular.noop');
});


it('should be resilient to trailing "index/"', function() {
browser.get('index-debug.html#!/api/ng/function/angular.noop/index/');
var pageBody = element(by.css('h1'));
expect(pageBody.getText()).toEqual('angular.noop');
});


it('should display formatted error messages on error doc pages', function() {
browser.get('index-debug.html#!error/ng/areq?p0=Missing&p1=not%20a%20function,%20got%20undefined');
expect(element(by.css('.minerr-errmsg')).getText()).toEqual("Argument 'Missing' is not a function, got undefined");
});
});
});