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

Commit b425246

Browse files
committed
chore(*): silence ng-closure-runner warnings during grunt minall
1 parent 8b39954 commit b425246

10 files changed

+53
-7
lines changed

src/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120

121121
/* minErr.js */
122122
"minErr": false,
123+
"noMinErr": false,
123124

124125
/* loader.js */
125126
"setupModuleLoader": false,

src/auto/injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ function createInjector(modulesToLoad, strictDi) {
890890
if (cache[serviceName] === INSTANTIATING) {
891891
delete cache[serviceName];
892892
}
893-
throw err;
893+
throw noMinErr('', '', err);
894894
} finally {
895895
path.shift();
896896
}

src/minErr.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ function isValidObjectMaxDepth(maxDepth) {
7979
* error from returned function, for cases when a particular type of error is useful.
8080
* @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
8181
*/
82-
8382
function minErr(module, ErrorConstructor) {
8483
ErrorConstructor = ErrorConstructor || Error;
8584
return function() {
@@ -111,3 +110,38 @@ function minErr(module, ErrorConstructor) {
111110
return new ErrorConstructor(message);
112111
};
113112
}
113+
114+
/**
115+
* @description
116+
*
117+
* In certain case (e.g. when catching and rethrowing an error), it is neither desirable nor
118+
* necessary to pass the error through `minErr()`. You can use this function to avoid warnings
119+
* produced by `ng-closire-runner` during `grunt minall`.
120+
*
121+
* Due to what arguments `ng-closure-runner` expects, the first two arguments must be static
122+
* strings. Therefore, you have to pass the actual error as 3rd argument (see example below).
123+
*
124+
* **WARNING**
125+
* Only use this function when you are certain that the thrown error should NOT be a `minErr`
126+
* instance;
127+
*
128+
* Example usage:
129+
*
130+
* ```js
131+
* try {
132+
* tryAndFail();
133+
* } catch (err) {
134+
* doSomeThing(err);
135+
* throw noMinErr('', '', err); // Functionally equivalent to `throw err`,
136+
* // but avoids `ng-closure-runner` warnings.
137+
* }
138+
* ```
139+
*
140+
* @param {string} ignoredCode - Ignored, but necessary for `ng-closure-runner`.
141+
* @param {string} ignoredTemplate - Ignored, but necessary for `ng-closure-runner`.
142+
* @param {*} error - The error object that will be returned.
143+
* @returns {*} - The passed in error.
144+
*/
145+
function noMinErr(ignoredCode, ignoredTemplate, err) {
146+
return err;
147+
}

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
15661566
// Reset the queue to trigger a new schedule next time there is a change
15671567
onChangesQueue = undefined;
15681568
if (errors.length) {
1569-
throw errors;
1569+
throw noMinErr('', '', errors);
15701570
}
15711571
});
15721572
} finally {

src/ng/directive/ngModelOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ModelOptions.prototype = {
4141
options = extend({}, options);
4242

4343
// Inherit options from the parent if specified by the value `"$inherit"`
44-
forEach(options, /* @this */ function(option, key) {
44+
forEach(options, /** @this */ function(option, key) {
4545
if (option === '$inherit') {
4646
if (key === '*') {
4747
inheritAll = true;

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
147147
// The json response type can be ignored if not supported, because JSON payloads are
148148
// parsed on the client-side regardless.
149149
if (responseType !== 'json') {
150-
throw e;
150+
throw noMinErr('', '', e);
151151
}
152152
}
153153
}

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ function $LocationProvider() {
894894
$location.url(oldUrl);
895895
$location.$$state = oldState;
896896

897-
throw e;
897+
throw noMinErr('', '', e);
898898
}
899899
}
900900

src/ng/rootScope.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ function $RootScopeProvider() {
11921192
} catch (e) {
11931193
$exceptionHandler(e);
11941194
// eslint-disable-next-line no-unsafe-finally
1195-
throw e;
1195+
throw noMinErr('', '', e);
11961196
}
11971197
}
11981198
},

test/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117

118118
/* minerr.js */
119119
"minErr": false,
120+
"noMinErr": false,
120121

121122
/* loader.js */
122123
"setupModuleLoader": false,

test/minErrSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,13 @@ describe('errors', function() {
166166
});
167167
});
168168
});
169+
170+
describe('noMinErr', function() {
171+
it('should return the 3rd argument', function() {
172+
expect(noMinErr('foo', 'bar', 'baz')).toBe('baz');
173+
expect(noMinErr('foo', 'bar', null)).toBe(null);
174+
expect(noMinErr('foo', 'bar')).toBeUndefined();
175+
expect(noMinErr('foo')).toBeUndefined();
176+
expect(noMinErr()).toBeUndefined();
177+
});
178+
});

0 commit comments

Comments
 (0)