refactor(core): drop getNgModuleDef error message in production (#60082)

Drops `getNgModuleDef` error message in production and replaces it with an error code.

PR Close #60082
This commit is contained in:
arturovt 2025-02-24 19:31:35 +02:00 committed by Miles Malerba
parent 9068163bf6
commit aa8dff80ba
4 changed files with 20 additions and 5 deletions

View file

@ -89,6 +89,8 @@ export const enum RuntimeErrorCode {
// (undocumented)
MISCONFIGURED_INCREMENTAL_HYDRATION = 508,
// (undocumented)
MISSING_DIRECTIVE_DEFINITION = 916,
// (undocumented)
MISSING_DOCUMENT = 210,
// (undocumented)
MISSING_GENERATED_DEF = 906,
@ -101,6 +103,8 @@ export const enum RuntimeErrorCode {
// (undocumented)
MISSING_LOCALE_DATA = 701,
// (undocumented)
MISSING_NG_MODULE_DEFINITION = 915,
// (undocumented)
MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
// (undocumented)
MISSING_SSR_CONTENT_INTEGRITY_MARKER = -507,

View file

@ -122,6 +122,8 @@ export const enum RuntimeErrorCode {
COMPONENT_ID_COLLISION = -912,
IMAGE_PERFORMANCE_WARNING = -913,
UNEXPECTED_ZONEJS_PRESENT_IN_ZONELESS_MODE = 914,
MISSING_NG_MODULE_DEFINITION = 915,
MISSING_DIRECTIVE_DEFINITION = 916,
// Signal integration errors
REQUIRED_INPUT_NO_VALUE = -950,

View file

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {RuntimeError, RuntimeErrorCode} from '../errors';
import {Type} from '../interface/type';
import type {NgModuleDef} from '../r3_symbols';
import {stringify} from '../util/stringify';
@ -16,8 +17,12 @@ export function getNgModuleDef<T>(type: any, throwIfNotFound: true): NgModuleDef
export function getNgModuleDef<T>(type: any): NgModuleDef<T> | null;
export function getNgModuleDef<T>(type: any, throwIfNotFound?: boolean): NgModuleDef<T> | null {
const ngModuleDef = type[NG_MOD_DEF] || null;
if (!ngModuleDef && throwIfNotFound === true) {
throw new Error(`Type ${stringify(type)} does not have 'ɵmod' property.`);
if (!ngModuleDef && throwIfNotFound) {
throw new RuntimeError(
RuntimeErrorCode.MISSING_NG_MODULE_DEFINITION,
(typeof ngDevMode === 'undefined' || ngDevMode) &&
`Type ${stringify(type)} does not have 'ɵmod' property.`,
);
}
return ngModuleDef;
}
@ -36,8 +41,12 @@ export function getDirectiveDef<T>(type: any, throwIfNotFound: true): DirectiveD
export function getDirectiveDef<T>(type: any): DirectiveDef<T> | null;
export function getDirectiveDef<T>(type: any, throwIfNotFound?: boolean): DirectiveDef<T> | null {
const def = type[NG_DIR_DEF] || null;
if (!def && throwIfNotFound === true) {
throw new Error(`Type ${stringify(type)} does not have 'ɵdir' property.`);
if (!def && throwIfNotFound) {
throw new RuntimeError(
RuntimeErrorCode.MISSING_DIRECTIVE_DEFINITION,
(typeof ngDevMode === 'undefined' || ngDevMode) &&
`Type ${stringify(type)} does not have 'ɵdir' property.`,
);
}
return def;
}

View file

@ -692,7 +692,7 @@
"standardizeConfig",
"storeLViewOnDestroy",
"stringify",
"stringify11",
"stringify12",
"stringifyCSSSelector",
"stripTrailingSlash",
"subscribeOn",