aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/compile.js
diff options
context:
space:
mode:
authorIgor Minar2013-05-24 11:00:14 -0700
committerVojta Jina2013-05-24 17:03:21 -0700
commitb8ea7f6aba2e675b85826b0bee1f21ddd7b866a5 (patch)
treef3b34e25e27d088bec9b698b246d49f86281de36 /src/ng/compile.js
parent88eaea8e7bf025a7805a5d20f5d47472e4f26f6f (diff)
downloadangular.js-b8ea7f6aba2e675b85826b0bee1f21ddd7b866a5.tar.bz2
feat(ngError): add error message compression and better error messages
- add toThrowNg matcher
Diffstat (limited to 'src/ng/compile.js')
-rw-r--r--src/ng/compile.js33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 96529d3c..be22482b 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -18,9 +18,6 @@
*/
-var NON_ASSIGNABLE_MODEL_EXPRESSION = 'Non-assignable model expression: ';
-
-
/**
* @ngdoc function
* @name ng.$compile
@@ -155,7 +152,6 @@ function $CompileProvider($provide) {
Suffix = 'Directive',
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
- MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: ',
urlSanitizationWhitelist = /^\s*(https?|ftp|mailto|file):/;
@@ -392,10 +388,6 @@ function $CompileProvider($provide) {
};
}
- function wrongMode(localName, mode) {
- throw Error("Unsupported '" + mode + "' for '" + localName + "'.");
- }
-
function safeAddClass($element, className) {
try {
$element.addClass(className);
@@ -669,7 +661,7 @@ function $CompileProvider($provide) {
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
- throw new Error(MULTI_ROOT_TEMPLATE_ERROR + directiveValue);
+ throw ngError(12, "Template for directive '{0}' must have exactly one root element.", directiveName);
}
replaceWith(jqCollection, $compileNode, compileNode);
@@ -755,7 +747,7 @@ function $CompileProvider($provide) {
}
value = $element[retrievalMethod]('$' + require + 'Controller');
if (!value && !optional) {
- throw Error("No controller: " + require);
+ throw ngError(13, "Controller '{0}', required by directive '{1}', can't be found!", require, directiveName);
}
return value;
} else if (isArray(require)) {
@@ -783,8 +775,8 @@ function $CompileProvider($provide) {
var parentScope = scope.$parent || scope;
- forEach(newIsolateScopeDirective.scope, function(definiton, scopeName) {
- var match = definiton.match(LOCAL_REGEXP) || [],
+ forEach(newIsolateScopeDirective.scope, function(definition, scopeName) {
+ var match = definition.match(LOCAL_REGEXP) || [],
attrName = match[3] || scopeName,
optional = (match[2] == '?'),
mode = match[1], // @, =, or &
@@ -815,8 +807,8 @@ function $CompileProvider($provide) {
parentSet = parentGet.assign || function() {
// reset the change, or we will throw this exception on every $digest
lastValue = scope[scopeName] = parentGet(parentScope);
- throw Error(NON_ASSIGNABLE_MODEL_EXPRESSION + attrs[attrName] +
- ' (directive: ' + newIsolateScopeDirective.name + ')');
+ throw ngError(14, "Expression '{0}' used with directive '{1}' is non-assignable!",
+ attrs[attrName], newIsolateScopeDirective.name);
};
lastValue = scope[scopeName] = parentGet(parentScope);
scope.$watch(function parentValueWatch() {
@@ -846,8 +838,8 @@ function $CompileProvider($provide) {
}
default: {
- throw Error('Invalid isolate scope definition for directive ' +
- newIsolateScopeDirective.name + ': ' + definiton);
+ throw ngError(15, "Invalid isolate scope definition for directive '{0}'. Definition: {... {1}: '{2}' ...}",
+ newIsolateScopeDirective.name, scopeName, definition);
}
}
});
@@ -1000,7 +992,8 @@ function $CompileProvider($provide) {
compileNode = $template[0];
if ($template.length != 1 || compileNode.nodeType !== 1) {
- throw new Error(MULTI_ROOT_TEMPLATE_ERROR + content);
+ throw ngError(16, "Template for directive '{0}' must have exactly one root element. Template: {1}",
+ origAsyncDirective.name, templateUrl);
}
tempTemplateAttrs = {$attr: {}};
@@ -1037,7 +1030,7 @@ function $CompileProvider($provide) {
linkQueue = null;
}).
error(function(response, code, headers, config) {
- throw Error('Failed to load template: ' + config.url);
+ throw ngError(17, 'Failed to load template: {0}', config.url);
});
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, controller) {
@@ -1065,8 +1058,8 @@ function $CompileProvider($provide) {
function assertNoDuplicate(what, previousDirective, directive, element) {
if (previousDirective) {
- throw Error('Multiple directives [' + previousDirective.name + ', ' +
- directive.name + '] asking for ' + what + ' on: ' + startingTag(element));
+ throw ngError(18, 'Multiple directives [{0}, {1}] asking for {2} on: {3}',
+ previousDirective.name, directive.name, what, startingTag(element));
}
}