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

chore(*): silence ng-closure-runner warnings during grunt minall #15439

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
1 change: 1 addition & 0 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

/* minErr.js */
"minErr": false,
"noMinErr": false,

/* loader.js */
"setupModuleLoader": false,
Expand Down
2 changes: 1 addition & 1 deletion src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ function createInjector(modulesToLoad, strictDi) {
if (cache[serviceName] === INSTANTIATING) {
delete cache[serviceName];
}
throw err;
throw noMinErr('', '', err);
} finally {
path.shift();
}
Expand Down
36 changes: 35 additions & 1 deletion src/minErr.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ function isValidObjectMaxDepth(maxDepth) {
* error from returned function, for cases when a particular type of error is useful.
* @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
*/

function minErr(module, ErrorConstructor) {
ErrorConstructor = ErrorConstructor || Error;
return function() {
Expand Down Expand Up @@ -111,3 +110,38 @@ function minErr(module, ErrorConstructor) {
return new ErrorConstructor(message);
};
}

/**
* @description
*
* In certain case (e.g. when catching and rethrowing an error), it is neither desirable nor
* necessary to pass the error through `minErr()`. You can use this function to avoid warnings
* produced by `ng-closire-runner` during `grunt minall`.
*
* Due to what arguments `ng-closure-runner` expects, the first two arguments must be static
* strings. Therefore, you have to pass the actual error as 3rd argument (see example below).
*
* **WARNING**
* Only use this function when you are certain that the thrown error should NOT be a `minErr`
* instance;
*
* Example usage:
*
* ```js
* try {
* tryAndFail();
* } catch (err) {
* doSomeThing(err);
* throw noMinErr('', '', err); // Functionally equivalent to `throw err`,
* // but avoids `ng-closure-runner` warnings.
* }
* ```
*
* @param {string} ignoredCode - Ignored, but necessary for `ng-closure-runner`.
* @param {string} ignoredTemplate - Ignored, but necessary for `ng-closure-runner`.
* @param {*} error - The error object that will be returned.
* @returns {*} - The passed in error.
*/
function noMinErr(ignoredCode, ignoredTemplate, err) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not thrilled about having to pass the first two string arguments.
Alternatively, we could teach ng-closure-runner to ignore noMinErr instances (i.e. not treat them as minErr instances, but don't log a warning either).

return err;
}
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
// Reset the queue to trigger a new schedule next time there is a change
onChangesQueue = undefined;
if (errors.length) {
throw errors;
throw noMinErr('', '', errors);
}
});
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/ng/directive/ngModelOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ModelOptions.prototype = {
options = extend({}, options);

// Inherit options from the parent if specified by the value `"$inherit"`
forEach(options, /* @this */ function(option, key) {
forEach(options, /** @this */ function(option, key) {
if (option === '$inherit') {
if (key === '*') {
inheritAll = true;
Expand Down
2 changes: 1 addition & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
// The json response type can be ignored if not supported, because JSON payloads are
// parsed on the client-side regardless.
if (responseType !== 'json') {
throw e;
throw noMinErr('', '', e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ng/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ function $LocationProvider() {
$location.url(oldUrl);
$location.$$state = oldState;

throw e;
throw noMinErr('', '', e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ function $RootScopeProvider() {
} catch (e) {
$exceptionHandler(e);
// eslint-disable-next-line no-unsafe-finally
throw e;
throw noMinErr('', '', e);
}
}
},
Expand Down
1 change: 1 addition & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@

/* minerr.js */
"minErr": false,
"noMinErr": false,

/* loader.js */
"setupModuleLoader": false,
Expand Down
10 changes: 10 additions & 0 deletions test/minErrSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,13 @@ describe('errors', function() {
});
});
});

describe('noMinErr', function() {
it('should return the 3rd argument', function() {
expect(noMinErr('foo', 'bar', 'baz')).toBe('baz');
expect(noMinErr('foo', 'bar', null)).toBe(null);
expect(noMinErr('foo', 'bar')).toBeUndefined();
expect(noMinErr('foo')).toBeUndefined();
expect(noMinErr()).toBeUndefined();
});
});