Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(common): make the error messages tree shakable #44663

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions goldens/public-api/common/errors.md
Expand Up @@ -6,6 +6,8 @@

// @public
export const enum RuntimeErrorCode {
// (undocumented)
INVALID_PIPE_ARGUMENT = 2100,
// (undocumented)
PARENT_NG_SWITCH_NOT_FOUND = 2000
}
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/errors.ts
Expand Up @@ -13,4 +13,6 @@
export const enum RuntimeErrorCode {
// NgSwitch errors
PARENT_NG_SWITCH_NOT_FOUND = 2000,
// Pipe errors
INVALID_PIPE_ARGUMENT = 2100
}
9 changes: 7 additions & 2 deletions packages/common/src/pipes/invalid_pipe_argument_error.ts
Expand Up @@ -6,8 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Type, ɵstringify as stringify} from '@angular/core';
import {Type, ɵRuntimeError as RuntimeError, ɵstringify as stringify} from '@angular/core';

import {RuntimeErrorCode} from '../errors';

export function invalidPipeArgumentError(type: Type<any>, value: Object) {
return Error(`InvalidPipeArgument: '${value}' for pipe '${stringify(type)}'`);
const errorMessage = (typeof ngDevMode === 'undefined' || ngDevMode) ?
`InvalidPipeArgument: '${value}' for pipe '${stringify(type)}'` :
'';
return new RuntimeError(RuntimeErrorCode.INVALID_PIPE_ARGUMENT, errorMessage);
}
9 changes: 5 additions & 4 deletions packages/common/test/pipes/number_pipe_spec.ts
Expand Up @@ -64,9 +64,10 @@ import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
it('should not support other objects', () => {
expect(() => pipe.transform({} as any))
.toThrowError(
`InvalidPipeArgument: '[object Object] is not a number' for pipe 'DecimalPipe'`);
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'DecimalPipe'`);
expect(() => pipe.transform('123abc'))
.toThrowError(`InvalidPipeArgument: '123abc is not a number' for pipe 'DecimalPipe'`);
.toThrowError(
`NG02100: InvalidPipeArgument: '123abc is not a number' for pipe 'DecimalPipe'`);
});
});

Expand Down Expand Up @@ -108,7 +109,7 @@ import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
it('should not support other objects', () => {
expect(() => pipe.transform({} as any))
.toThrowError(
`InvalidPipeArgument: '[object Object] is not a number' for pipe 'PercentPipe'`);
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'PercentPipe'`);
});
});
});
Expand Down Expand Up @@ -168,7 +169,7 @@ import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
it('should not support other objects', () => {
expect(() => pipe.transform({} as any))
.toThrowError(
`InvalidPipeArgument: '[object Object] is not a number' for pipe 'CurrencyPipe'`);
`NG02100: InvalidPipeArgument: '[object Object] is not a number' for pipe 'CurrencyPipe'`);
});

it('should warn if you are using the v4 signature', () => {
Expand Down
Expand Up @@ -1878,7 +1878,7 @@
"name": "stringify"
},
{
"name": "stringify6"
"name": "stringify7"
},
{
"name": "stringifyCSSSelector"
Expand Down