2017-01-27 21:19:00 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2017-01-27 21:19:00 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-08 01:37:00 +00:00
|
|
|
import {ERROR_DETAILS_PAGE_BASE_URL} from './error_details_base_url';
|
2017-01-27 21:19:00 +00:00
|
|
|
|
2021-12-08 01:37:00 +00:00
|
|
|
/**
|
|
|
|
|
* The list of error codes used in runtime code of the `core` package.
|
|
|
|
|
* Reserved error code range: 100-999.
|
|
|
|
|
*
|
|
|
|
|
* Note: the minus sign denotes the fact that a particular code has a detailed guide on
|
|
|
|
|
* angular.io. This extra annotation is needed to avoid introducing a separate set to store
|
|
|
|
|
* error codes which have guides, which might leak into runtime code.
|
|
|
|
|
*
|
|
|
|
|
* Full list of available error guides can be found at https://angular.io/errors.
|
|
|
|
|
*/
|
|
|
|
|
export const enum RuntimeErrorCode {
|
|
|
|
|
// Change Detection Errors
|
|
|
|
|
EXPRESSION_CHANGED_AFTER_CHECKED = -100,
|
|
|
|
|
RECURSIVE_APPLICATION_REF_TICK = 101,
|
|
|
|
|
|
|
|
|
|
// Dependency Injection Errors
|
|
|
|
|
CYCLIC_DI_DEPENDENCY = -200,
|
|
|
|
|
PROVIDER_NOT_FOUND = -201,
|
2021-12-02 00:15:32 +00:00
|
|
|
INVALID_FACTORY_DEPENDENCY = 202,
|
2022-05-27 11:52:34 +00:00
|
|
|
MISSING_INJECTION_CONTEXT = -203,
|
2021-12-02 00:15:32 +00:00
|
|
|
INVALID_INJECTION_TOKEN = 204,
|
|
|
|
|
INJECTOR_ALREADY_DESTROYED = 205,
|
2022-05-02 14:40:44 +00:00
|
|
|
PROVIDER_IN_WRONG_CONTEXT = 207,
|
2022-06-17 02:00:19 +00:00
|
|
|
MISSING_INJECTION_TOKEN = 208,
|
2022-11-28 22:43:18 +00:00
|
|
|
INVALID_MULTI_PROVIDER = -209,
|
2017-01-27 21:19:00 +00:00
|
|
|
|
2021-12-08 01:37:00 +00:00
|
|
|
// Template Errors
|
|
|
|
|
MULTIPLE_COMPONENTS_MATCH = -300,
|
|
|
|
|
EXPORT_NOT_FOUND = -301,
|
|
|
|
|
PIPE_NOT_FOUND = -302,
|
|
|
|
|
UNKNOWN_BINDING = 303,
|
|
|
|
|
UNKNOWN_ELEMENT = 304,
|
|
|
|
|
TEMPLATE_STRUCTURE_ERROR = 305,
|
2021-12-02 00:15:32 +00:00
|
|
|
INVALID_EVENT_BINDING = 306,
|
2022-09-30 07:24:34 +00:00
|
|
|
HOST_DIRECTIVE_UNRESOLVABLE = 307,
|
|
|
|
|
HOST_DIRECTIVE_NOT_STANDALONE = 308,
|
|
|
|
|
DUPLICATE_DIRECTITVE = 309,
|
|
|
|
|
HOST_DIRECTIVE_COMPONENT = 310,
|
|
|
|
|
HOST_DIRECTIVE_UNDEFINED_BINDING = 311,
|
|
|
|
|
HOST_DIRECTIVE_CONFLICTING_ALIAS = 312,
|
2021-12-08 01:37:00 +00:00
|
|
|
|
|
|
|
|
// Bootstrap Errors
|
|
|
|
|
MULTIPLE_PLATFORMS = 400,
|
|
|
|
|
PLATFORM_NOT_FOUND = 401,
|
2023-03-08 20:25:22 +00:00
|
|
|
MISSING_REQUIRED_INJECTABLE_IN_BOOTSTRAP = 402,
|
2022-12-14 10:19:20 +00:00
|
|
|
BOOTSTRAP_COMPONENTS_NOT_FOUND = -403,
|
2022-04-05 04:28:01 +00:00
|
|
|
PLATFORM_ALREADY_DESTROYED = 404,
|
2021-12-08 01:37:00 +00:00
|
|
|
ASYNC_INITIALIZERS_STILL_RUNNING = 405,
|
2022-04-05 04:28:01 +00:00
|
|
|
APPLICATION_REF_ALREADY_DESTROYED = 406,
|
2022-06-29 19:01:33 +00:00
|
|
|
RENDERER_NOT_FOUND = 407,
|
2021-12-08 01:37:00 +00:00
|
|
|
|
|
|
|
|
// Styling Errors
|
|
|
|
|
|
|
|
|
|
// Declarations Errors
|
|
|
|
|
|
|
|
|
|
// i18n Errors
|
2021-12-02 00:15:32 +00:00
|
|
|
INVALID_I18N_STRUCTURE = 700,
|
2022-06-23 05:13:03 +00:00
|
|
|
MISSING_LOCALE_DATA = 701,
|
2021-12-08 01:37:00 +00:00
|
|
|
|
2022-05-02 13:27:28 +00:00
|
|
|
// standalone errors
|
|
|
|
|
IMPORT_PROVIDERS_FROM_STANDALONE = 800,
|
|
|
|
|
|
2021-12-08 01:37:00 +00:00
|
|
|
// JIT Compilation Errors
|
2021-12-02 00:15:32 +00:00
|
|
|
// Other
|
|
|
|
|
INVALID_DIFFER_INPUT = 900,
|
|
|
|
|
NO_SUPPORTING_DIFFER_FACTORY = 901,
|
|
|
|
|
VIEW_ALREADY_ATTACHED = 902,
|
|
|
|
|
INVALID_INHERITANCE = 903,
|
|
|
|
|
UNSAFE_VALUE_IN_RESOURCE_URL = 904,
|
2022-04-21 02:31:35 +00:00
|
|
|
UNSAFE_VALUE_IN_SCRIPT = 905,
|
|
|
|
|
MISSING_GENERATED_DEF = 906,
|
|
|
|
|
TYPE_IS_NOT_STANDALONE = 907,
|
2022-06-23 16:50:02 +00:00
|
|
|
MISSING_ZONEJS = 908,
|
|
|
|
|
UNEXPECTED_ZONE_STATE = 909,
|
2022-11-11 00:49:53 +00:00
|
|
|
UNSAFE_IFRAME_ATTRS = -910,
|
2017-01-27 21:19:00 +00:00
|
|
|
}
|
2017-03-14 16:16:15 +00:00
|
|
|
|
2022-01-21 21:02:40 +00:00
|
|
|
/**
|
|
|
|
|
* Class that represents a runtime error.
|
|
|
|
|
* Formats and outputs the error message in a consistent way.
|
|
|
|
|
*
|
|
|
|
|
* Example:
|
|
|
|
|
* ```
|
|
|
|
|
* throw new RuntimeError(
|
|
|
|
|
* RuntimeErrorCode.INJECTOR_ALREADY_DESTROYED,
|
|
|
|
|
* ngDevMode && 'Injector has already been destroyed.');
|
|
|
|
|
* ```
|
|
|
|
|
*
|
|
|
|
|
* Note: the `message` argument contains a descriptive error message as a string in development
|
|
|
|
|
* mode (when the `ngDevMode` is defined). In production mode (after tree-shaking pass), the
|
|
|
|
|
* `message` argument becomes `false`, thus we account for it in the typings and the runtime logic.
|
|
|
|
|
*/
|
|
|
|
|
export class RuntimeError<T extends number = RuntimeErrorCode> extends Error {
|
|
|
|
|
constructor(public code: T, message: null|false|string) {
|
2021-12-08 01:37:00 +00:00
|
|
|
super(formatRuntimeError<T>(code, message));
|
|
|
|
|
}
|
2017-03-14 16:16:15 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-21 21:02:40 +00:00
|
|
|
/**
|
|
|
|
|
* Called to format a runtime error.
|
|
|
|
|
* See additional info on the `message` argument type in the `RuntimeError` class description.
|
|
|
|
|
*/
|
|
|
|
|
export function formatRuntimeError<T extends number = RuntimeErrorCode>(
|
|
|
|
|
code: T, message: null|false|string): string {
|
2021-12-08 01:37:00 +00:00
|
|
|
// Error code might be a negative number, which is a special marker that instructs the logic to
|
|
|
|
|
// generate a link to the error details page on angular.io.
|
2022-11-08 01:16:32 +00:00
|
|
|
// We also prepend `0` to non-compile-time errors.
|
2022-01-21 21:02:40 +00:00
|
|
|
const fullCode = `NG0${Math.abs(code)}`;
|
2021-12-08 01:37:00 +00:00
|
|
|
|
2022-06-03 10:18:04 +00:00
|
|
|
let errorMessage = `${fullCode}${message ? ': ' + message.trim() : ''}`;
|
2017-03-14 16:16:15 +00:00
|
|
|
|
2022-01-21 21:02:40 +00:00
|
|
|
if (ngDevMode && code < 0) {
|
2022-06-03 10:18:04 +00:00
|
|
|
const addPeriodSeparator = !errorMessage.match(/[.,;!?]$/);
|
|
|
|
|
const separator = addPeriodSeparator ? '.' : '';
|
|
|
|
|
errorMessage =
|
|
|
|
|
`${errorMessage}${separator} Find more at ${ERROR_DETAILS_PAGE_BASE_URL}/${fullCode}`;
|
2021-12-08 01:37:00 +00:00
|
|
|
}
|
|
|
|
|
return errorMessage;
|
2020-05-19 19:08:49 +00:00
|
|
|
}
|