mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(common): drop error messages in production (#60415)
Drops more error messages in production. PR Close #60415
This commit is contained in:
parent
43cbc58254
commit
5317979738
6 changed files with 52 additions and 12 deletions
|
|
@ -9,10 +9,16 @@ export const enum RuntimeErrorCode {
|
|||
// (undocumented)
|
||||
EQUALITY_NG_SWITCH_DIFFERENCE = 2001,
|
||||
// (undocumented)
|
||||
INVALID_DIGIT_INFO = 2306,
|
||||
// (undocumented)
|
||||
INVALID_INPUT = 2952,
|
||||
// (undocumented)
|
||||
INVALID_INTEGER_LITERAL = 2305,
|
||||
// (undocumented)
|
||||
INVALID_LOADER_ARGUMENTS = 2959,
|
||||
// (undocumented)
|
||||
INVALID_NUMBER_OF_DIGITS_AFTER_FRACTION = 2307,
|
||||
// (undocumented)
|
||||
INVALID_PIPE_ARGUMENT = 2100,
|
||||
// (undocumented)
|
||||
INVALID_TO_DATE_CONVERSION = 2302,
|
||||
|
|
@ -21,14 +27,20 @@ export const enum RuntimeErrorCode {
|
|||
// (undocumented)
|
||||
LCP_IMG_NGSRC_MODIFIED = 2964,
|
||||
// (undocumented)
|
||||
LOCALE_DATA_UNDEFINED = 2304,
|
||||
// (undocumented)
|
||||
MISSING_BUILTIN_LOADER = 2962,
|
||||
// (undocumented)
|
||||
MISSING_EXTRA_LOCALE_DATA_FOR_LOCALE = 2303,
|
||||
// (undocumented)
|
||||
MISSING_NECESSARY_LOADER = 2963,
|
||||
// (undocumented)
|
||||
NG_FOR_MISSING_DIFFER = -2200,
|
||||
// (undocumented)
|
||||
NG_IF_NOT_A_TEMPLATE_REF = 2020,
|
||||
// (undocumented)
|
||||
NO_PLURAL_MESSAGE_FOUND = 2308,
|
||||
// (undocumented)
|
||||
OVERSIZED_IMAGE = 2960,
|
||||
// (undocumented)
|
||||
OVERSIZED_PLACEHOLDER = 2965,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ export const enum RuntimeErrorCode {
|
|||
UNEXPECTED_TRANSLATION_TYPE = 2302,
|
||||
UNKNOWN_ZONE_WIDTH = 2302,
|
||||
INVALID_TO_DATE_CONVERSION = 2302,
|
||||
MISSING_EXTRA_LOCALE_DATA_FOR_LOCALE = 2303,
|
||||
LOCALE_DATA_UNDEFINED = 2304,
|
||||
INVALID_INTEGER_LITERAL = 2305,
|
||||
INVALID_DIGIT_INFO = 2306,
|
||||
INVALID_NUMBER_OF_DIGITS_AFTER_FRACTION = 2307,
|
||||
NO_PLURAL_MESSAGE_FOUND = 2308,
|
||||
|
||||
// Keep 2800 - 2900 for Http Errors.
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {ɵRuntimeError as RuntimeError} from '@angular/core';
|
||||
|
||||
import {
|
||||
getLocaleNumberFormat,
|
||||
getLocaleNumberSymbol,
|
||||
|
|
@ -13,6 +15,7 @@ import {
|
|||
NumberFormatStyle,
|
||||
NumberSymbol,
|
||||
} from './locale_data_api';
|
||||
import {RuntimeErrorCode} from '../errors';
|
||||
|
||||
export const NUMBER_FORMAT_REGEXP = /^(\d+)?\.((\d+)(-(\d+))?)?$/;
|
||||
const MAX_DIGITS = 22;
|
||||
|
|
@ -55,7 +58,10 @@ function formatNumberToLocaleString(
|
|||
if (digitsInfo) {
|
||||
const parts = digitsInfo.match(NUMBER_FORMAT_REGEXP);
|
||||
if (parts === null) {
|
||||
throw new Error(`${digitsInfo} is not a valid digit info`);
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.INVALID_DIGIT_INFO,
|
||||
ngDevMode && `${digitsInfo} is not a valid digit info`,
|
||||
);
|
||||
}
|
||||
const minIntPart = parts[1];
|
||||
const minFractionPart = parts[3];
|
||||
|
|
@ -436,8 +442,10 @@ function parseNumber(num: number): ParsedNumber {
|
|||
*/
|
||||
function roundNumber(parsedNumber: ParsedNumber, minFrac: number, maxFrac: number) {
|
||||
if (minFrac > maxFrac) {
|
||||
throw new Error(
|
||||
`The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`,
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.INVALID_NUMBER_OF_DIGITS_AFTER_FRACTION,
|
||||
ngDevMode &&
|
||||
`The minimum number of digits after fraction (${minFrac}) is higher than the maximum (${maxFrac}).`,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -509,7 +517,10 @@ function roundNumber(parsedNumber: ParsedNumber, minFrac: number, maxFrac: numbe
|
|||
export function parseIntAutoRadix(text: string): number {
|
||||
const result: number = parseInt(text);
|
||||
if (isNaN(result)) {
|
||||
throw new Error('Invalid integer literal when parsing ' + text);
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.INVALID_INTEGER_LITERAL,
|
||||
ngDevMode && 'Invalid integer literal when parsing ' + text,
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,11 @@ import {
|
|||
ɵgetLocaleCurrencyCode,
|
||||
ɵgetLocalePluralCase,
|
||||
ɵLocaleDataIndex,
|
||||
ɵRuntimeError as RuntimeError,
|
||||
} from '@angular/core';
|
||||
|
||||
import {CURRENCIES_EN, CurrenciesSymbols} from './currencies';
|
||||
import {RuntimeErrorCode} from '../errors';
|
||||
|
||||
/**
|
||||
* Format styles that can be used to represent numbers.
|
||||
|
|
@ -599,10 +601,12 @@ export const getLocalePluralCase: (locale: string) => (value: number) => Plural
|
|||
|
||||
function checkFullData(data: any) {
|
||||
if (!data[ɵLocaleDataIndex.ExtraData]) {
|
||||
throw new Error(
|
||||
`Missing extra locale data for the locale "${
|
||||
data[ɵLocaleDataIndex.LocaleId]
|
||||
}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`,
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.MISSING_EXTRA_LOCALE_DATA_FOR_LOCALE,
|
||||
ngDevMode &&
|
||||
`Missing extra locale data for the locale "${
|
||||
data[ɵLocaleDataIndex.LocaleId]
|
||||
}". Use "registerLocaleData" to load new data. See the "I18n guide" on angular.io to know more.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -715,7 +719,10 @@ function getLastDefinedValue<T>(data: T[], index: number): T {
|
|||
return data[i];
|
||||
}
|
||||
}
|
||||
throw new Error('Locale data API: locale data undefined');
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.LOCALE_DATA_UNDEFINED,
|
||||
ngDevMode && 'Locale data API: locale data undefined',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -6,9 +6,10 @@
|
|||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {Inject, Injectable, LOCALE_ID} from '@angular/core';
|
||||
import {Inject, Injectable, LOCALE_ID, ɵRuntimeError as RuntimeError} from '@angular/core';
|
||||
|
||||
import {getLocalePluralCase, Plural} from './locale_data_api';
|
||||
import {RuntimeErrorCode} from '../errors';
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
|
|
@ -49,7 +50,10 @@ export function getPluralCategory(
|
|||
return 'other';
|
||||
}
|
||||
|
||||
throw new Error(`No plural message found for value "${value}"`);
|
||||
throw new RuntimeError(
|
||||
RuntimeErrorCode.NO_PLURAL_MESSAGE_FOUND,
|
||||
ngDevMode && `No plural message found for value "${value}"`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ describe('l10n', () => {
|
|||
const l10n = new NgLocaleLocalization('ro');
|
||||
// 2 -> 'few'
|
||||
getPluralCategory(2, ['one'], l10n);
|
||||
}).toThrowError('No plural message found for value "2"');
|
||||
}).toThrowError('NG02308: No plural message found for value "2"');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue