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

Commit d7a73e4

Browse files
chore(doc-gen): add formatted error messages to error pages
This got missed in the doc migration: When there is an error in an Angular app, extra information is placed in the URL, which can be used by the docs application to display a more useful message. This fix adds that back in. The error message templates are extracted by the minerr tool during build and put into the errors.json file. The errors-doc processor will load this up and attach these message templates to the error docs. The display of these templates was already in place, via the errorDisplay directive in docs/app/js/errors.js. (Also, moved the error.template.html file into the angular.js repository from the dgeni-packages repository as this is specific to the angular.js project and all the other error related stuff is in here. Finally, also, added an e2e test that checks that minerr formatted messages are displayed correctly. Closes #6363
1 parent e6c35e1 commit d7a73e4

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

docs/config/processors/error-docs.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,15 @@ module.exports = {
88
runAfter: ['tags-extracted'],
99
init: function(config, injectables) {
1010
injectables.value('errorNamespaces', {});
11+
12+
var minerrInfoPath = config.get('processing.errors.minerrInfoPath');
13+
if ( !minerrInfoPath ) {
14+
throw new Error('Error in configuration: Please provide a path to the minerr info file (errors.json) ' +
15+
'in the `config.processing.errors.minerrInfoPath` property');
16+
}
17+
injectables.value('minerrInfo', require(minerrInfoPath));
1118
},
12-
process: function(docs, partialNames, errorNamespaces) {
19+
process: function(docs, partialNames, errorNamespaces, minerrInfo) {
1320

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

42+
doc.formattedErrorMessage = minerrInfo.errors[doc.namespace.name][doc.name];
43+
3544
}
3645

3746
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{% extends "base.template.html" %}
2+
3+
{% block content %}
4+
<h1>Error: {$ doc.id $}
5+
<div><span class='hint'>{$ doc.fullName $}</span></div>
6+
</h1>
7+
8+
<div>
9+
<pre class="minerr-errmsg" error-display="{$ doc.formattedErrorMessage $}">{$ doc.formattedErrorMessage $}</pre>
10+
</div>
11+
12+
<h2>Description</h2>
13+
<div class="description">
14+
{$ doc.description | marked $}
15+
</div>
16+
17+
{% endblock %}

docs/docs.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ module.exports = function(config) {
3131
});
3232
config.set('processing.examples.dependencyPath', '../../..');
3333

34+
35+
config.set('processing.errors.minerrInfoPath', path.resolve(basePath, '../build/errors.json'));
36+
3437
config.set('rendering.outputFolder', '../build/docs');
3538

3639
config.set('logging.level', 'info');

test/e2e/docsAppE2E.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,31 @@ describe('docs.angularjs.org', function () {
3939
expect(code.getText()).toContain('guest!!!');
4040
});
4141

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

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

56+
5457
it('should be resilient to trailing "index/"', function() {
5558
browser.get('index-debug.html#!/api/ng/function/angular.noop/index/');
5659
var pageBody = element(by.css('h1'));
5760
expect(pageBody.getText()).toEqual('angular.noop');
5861
});
62+
63+
64+
it('should display formatted error messages on error doc pages', function() {
65+
browser.get('index-debug.html#!error/ng/areq?p0=Missing&p1=not%20a%20function,%20got%20undefined');
66+
expect(element(by.css('.minerr-errmsg')).getText()).toEqual("Argument 'Missing' is not a function, got undefined");
67+
});
5968
});
6069
});

0 commit comments

Comments
 (0)