|
29 | 29 | * error from returned function, for cases when a particular type of error is useful.
|
30 | 30 | * @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
|
31 | 31 | */
|
32 |
| - |
33 | 32 | function minErr(module, ErrorConstructor) {
|
34 | 33 | ErrorConstructor = ErrorConstructor || Error;
|
35 | 34 | return function() {
|
@@ -63,3 +62,38 @@ function minErr(module, ErrorConstructor) {
|
63 | 62 | return new ErrorConstructor(message);
|
64 | 63 | };
|
65 | 64 | }
|
| 65 | + |
| 66 | +/** |
| 67 | + * @description |
| 68 | + * |
| 69 | + * In certain case (e.g. when catching and rethrowing an error), it is neither desirable nor |
| 70 | + * necessary to pass the error through `minErr()`. You can use this function to avoid warnings |
| 71 | + * produced by `ng-closire-runner` during `grunt minall`. |
| 72 | + * |
| 73 | + * Due to what arguments `ng-closure-runner` expects, the first two arguments must be static |
| 74 | + * strings. Therefore, you have to pass the actual error as 3rd argument (see example below). |
| 75 | + * |
| 76 | + * **WARNING** |
| 77 | + * Only use this function when you are certain that the thrown error should NOT be a `minErr` |
| 78 | + * instance; |
| 79 | + * |
| 80 | + * Example usage: |
| 81 | + * |
| 82 | + * ```js |
| 83 | + * try { |
| 84 | + * tryAndFail(); |
| 85 | + * } catch (err) { |
| 86 | + * doSomeThing(err); |
| 87 | + * throw noMinErr('', '', err); // Functionally equivalent to `throw err`, |
| 88 | + * // but avoids `ng-closuer-runner` warnings. |
| 89 | + * } |
| 90 | + * ``` |
| 91 | + * |
| 92 | + * @param {string} ignoredCode - Ignored, but necessary for `ng-closure-runner`. |
| 93 | + * @param {string} ignoredTemplate - Ignored, but necessary for `ng-closure-runner`. |
| 94 | + * @param {*} error - The error object that will be returned. |
| 95 | + * @returns {*} - The passed in error. |
| 96 | + */ |
| 97 | +function noMinErr(ignoredCode, ignoredTemplate, err) { |
| 98 | + return err; |
| 99 | +} |
0 commit comments