From 1f1e2283c9b0af49cb23c9ee68e433c38e8e0221 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 20 Feb 2014 06:24:23 +0000 Subject: [PATCH 1/2] 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. --- docs/config/processors/error-docs.js | 11 ++++++++++- docs/config/templates/error.template.html | 17 +++++++++++++++++ docs/docs.config.js | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 docs/config/templates/error.template.html diff --git a/docs/config/processors/error-docs.js b/docs/config/processors/error-docs.js index 80a7b996d432..3fed96c578d5 100644 --- a/docs/config/processors/error-docs.js +++ b/docs/config/processors/error-docs.js @@ -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) { @@ -32,6 +39,8 @@ module.exports = { namespaceDoc.errors.push(doc); doc.namespace = namespaceDoc; + doc.formattedErrorMessage = minerrInfo.errors[doc.namespace.name][doc.name]; + } }); diff --git a/docs/config/templates/error.template.html b/docs/config/templates/error.template.html new file mode 100644 index 000000000000..f48b397b87e7 --- /dev/null +++ b/docs/config/templates/error.template.html @@ -0,0 +1,17 @@ +{% extends "base.template.html" %} + +{% block content %} +

Error: {$ doc.id $} +
{$ doc.fullName $}
+

+ +
+
{$ doc.formattedErrorMessage $}
+
+ +

Description

+
+ {$ doc.description | marked $} +
+ +{% endblock %} \ No newline at end of file diff --git a/docs/docs.config.js b/docs/docs.config.js index 536728fba27f..afe982fda7c5 100644 --- a/docs/docs.config.js +++ b/docs/docs.config.js @@ -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'); From 8520158f62e86e58fa66c7f2e81180eae071a7b3 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 20 Feb 2014 10:57:40 +0000 Subject: [PATCH 2/2] test(docs-app): check that minerr formatted messages are displayed --- test/e2e/docsAppE2E.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/e2e/docsAppE2E.js b/test/e2e/docsAppE2E.js index da0726b86fd3..8fe30c38b219 100644 --- a/test/e2e/docsAppE2E.js +++ b/test/e2e/docsAppE2E.js @@ -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"); + }); }); }); \ No newline at end of file