Skip to content

Commit f1c2db1

Browse files
committed
Test fixes for new exception handler
1 parent 9eb7d73 commit f1c2db1

File tree

29 files changed

+225
-195
lines changed

29 files changed

+225
-195
lines changed

@types/core/compile/compile.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ export class CompileProvider {
126126
| ((
127127
$injector: ng.InjectorService,
128128
$interpolate: any,
129-
$exceptionHandler: import("../../services/exception/exception-handler.js").ErrorHandler,
129+
$exceptionHandler: ng.ExceptionHandlerService,
130130
$templateRequest: ng.TemplateRequestService,
131131
$parse: ng.ParseService,
132132
$controller: any,
133-
$rootScope: import("../scope/scope.js").Scope,
133+
$rootScope: ng.Scope,
134134
$sce: any,
135135
$animate: ng.AnimateService,
136136
) => (

@types/directive/bind/bind.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* @returns {import('../../interface.ts').Directive}
2+
* @returns {ng.Directive}
33
*/
4-
export function ngBindDirective(): import("../../interface.ts").Directive;
4+
export function ngBindDirective(): ng.Directive;
55
/**
66
* @returns {import('../../interface.ts').Directive}
77
*/

@types/directive/include/include.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* @param {ng.TemplateRequestService} $templateRequest
44
* @param {import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction} $anchorScroll
55
* @param {ng.AnimateService} $animate
6-
* @param {import('../../services/exception/interface.ts').ErrorHandler} $exceptionHandler
7-
* @returns {import('../../interface.ts').Directive}
6+
* @param {ng.ExceptionHandlerService} $exceptionHandler
7+
* @returns {ng.Directive}
88
*/
99
export function ngIncludeDirective(
1010
$templateRequest: ng.TemplateRequestService,
1111
$anchorScroll: import("../../services/anchor-scroll/anchor-scroll.js").AnchorScrollFunction,
1212
$animate: ng.AnimateService,
13-
$exceptionHandler: import("../../services/exception/interface.ts").ErrorHandler,
14-
): import("../../interface.ts").Directive;
13+
$exceptionHandler: ng.ExceptionHandlerService,
14+
): ng.Directive;
1515
export namespace ngIncludeDirective {
1616
let $inject: string[];
1717
}

@types/directive/model/model.d.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ export class NgModelController {
4949
static $nonscope: boolean;
5050
static $inject: string[];
5151
/**
52-
* @param {import('../../core/scope/scope.js').Scope} $scope
53-
* @param {import('../../services/exception/exception-handler.js').ErrorHandler} $exceptionHandler
54-
* @param {import('../../core/compile/attributes.js').Attributes} $attr
52+
* @param {ng.Scope} $scope
53+
* @param {ng.ExceptionHandlerService} $exceptionHandler
54+
* @param {ng.Attributes} $attr
5555
* @param {Element} $element
56-
* @param {import("../../core/parse/interface.ts").ParseService} $parse
56+
* @param {ng.ParseService} $parse
5757
* @param {ng.AnimateService} $animate
5858
* @param {*} $interpolate
5959
*/
6060
constructor(
61-
$scope: import("../../core/scope/scope.js").Scope,
62-
$exceptionHandler: import("../../services/exception/exception-handler.js").ErrorHandler,
63-
$attr: import("../../core/compile/attributes.js").Attributes,
61+
$scope: ng.Scope,
62+
$exceptionHandler: ng.ExceptionHandlerService,
63+
$attr: ng.Attributes,
6464
$element: Element,
65-
$parse: import("../../core/parse/interface.ts").ParseService,
65+
$parse: ng.ParseService,
6666
$animate: ng.AnimateService,
6767
$interpolate: any,
6868
);
@@ -123,21 +123,21 @@ export class NgModelController {
123123
$$parsedNgModelAssign: (context: any, value: any) => any;
124124
/**
125125
* @type {import("../../core/parse/interface.ts").CompiledExpression |
126-
* (function(import("../../core/scope/scope.js").Scope): any)}
126+
* (function(ng.Scope): any)}
127127
*/
128128
$$ngModelGet:
129129
| import("../../core/parse/interface.ts").CompiledExpression
130-
| ((arg0: import("../../core/scope/scope.js").Scope) => any);
130+
| ((arg0: ng.Scope) => any);
131131
$$ngModelSet: (context: any, value: any) => any;
132132
$$pendingDebounce: number;
133133
$$parserValid: boolean;
134134
/** @type {string} */
135135
$$parserName: string;
136136
/** @type {number} */
137137
$$currentValidationRunId: number;
138-
/** @type {import('../../core/scope/scope.js').Scope} */
139-
$$scope: import("../../core/scope/scope.js").Scope;
140-
$$attr: import("../../core/compile/attributes.js").Attributes;
138+
/** @type {ng.Scope} */
139+
$$scope: ng.Scope;
140+
$$attr: ng.Attributes;
141141
$$element: Element;
142142
$$animate: import("../../interface.ts").AnimateService;
143143
$$parse: import("../../core/parse/interface.ts").ParseService;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
*
33
* @param {ng.CompileService} $compile
4-
* @param {import("../../core/parse/interface.ts").ParseService} $parse
5-
* @returns {import("../../interface.ts").Directive}
4+
* @param {ng.ParseService} $parse
5+
* @returns {ng.Directive}
66
*/
77
export function ngOptionsDirective(
88
$compile: ng.CompileService,
9-
$parse: import("../../core/parse/interface.ts").ParseService,
10-
): import("../../interface.ts").Directive;
9+
$parse: ng.ParseService,
10+
): ng.Directive;
1111
export namespace ngOptionsDirective {
1212
let $inject: string[];
1313
}

@types/router/url/url-service.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,7 @@ export class UrlService {
6060
getHash(): string;
6161
$get: (
6262
| string
63-
| ((
64-
$location: import("../../services/location/location.js").Location,
65-
$rootScope: import("../../core/scope/scope.js").Scope,
66-
) => UrlService)
63+
| (($location: ng.LocationService, $rootScope: ng.Scope) => UrlService)
6764
)[];
6865
/**
6966
* @returns {string}
Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,56 @@
11
/**
2-
* Handles uncaught exceptions thrown in AngularTS expressions.
2+
* Unified exception handler used throughout AngularTS.
33
*
4-
* By default, this service delegates to `$log.error()`, logging the exception to the browser console.
5-
* You can override this behavior to provide custom exception handling—such as reporting errors
6-
* to a backend server, or altering the log level used.
4+
* This service receives uncaught exceptions from both synchronous and asynchronous operations.
5+
* Its purpose is to provide a central point through which the framework
6+
* surfaces errors.
77
*
8-
* ## Default Behavior
8+
* By default, `$exceptionHandler` simply rethrows the exception. This ensures fail-fast
9+
* behavior, making errors visible immediately in development and in unit tests.
10+
* Applications may override this service to introduce custom error handling.
911
*
10-
* Uncaught exceptions within AngularTS expressions are intercepted and passed to this service.
11-
* The default implementation logs the error using `$log.error(exception, cause)`.
12-
*
13-
* ## Custom Implementation
14-
*
15-
* You can override the default `$exceptionHandler` by providing your own factory. This allows you to:
16-
* - Log errors to a remote server
17-
* - Change the log level (e.g., from `error` to `warn`)
18-
* - Trigger custom error-handling workflows
19-
*
20-
* ### Example: Overriding `$exceptionHandler`
12+
* ### Example: Custom `$exceptionHandler`
2113
*
2214
* ```js
2315
* angular
24-
* .module('exceptionOverwrite', [])
25-
* .factory('$exceptionHandler', ['$log', 'logErrorsToBackend', function($log, logErrorsToBackend) {
26-
* return function myExceptionHandler(exception, cause) {
27-
* logErrorsToBackend(exception, cause);
28-
* $log.warn(exception, cause); // Use warn instead of error
16+
* .module('app')
17+
* .factory('$exceptionHandler', function(myLogger) {
18+
* return function handleError(error) {
19+
* myLogger.capture(error);
20+
* // Rethrow to preserve fail-fast behavior:
21+
* throw error;
2922
* };
30-
* }]);
23+
* });
3124
* ```
32-
* - You may also manually invoke the exception handler:
25+
*
26+
* IMPORTANT: custom implementation should always rethrow the error as the framework assumes that `$exceptionHandler` always does the throwing.
27+
*
28+
* ### Manual Invocation
29+
*
30+
* You can invoke the exception handler directly when catching errors in your own code:
3331
*
3432
* ```js
3533
* try {
36-
* // Some code that might throw
37-
* } catch (e) {
38-
* $exceptionHandler(e, 'optional context');
34+
* riskyOperation();
35+
* } catch (err) {
36+
* $exceptionHandler(err);
3937
* }
4038
* ```
4139
*
4240
* @see {@link angular.ErrorHandler AngularTS ErrorHandler}
4341
*/
44-
/** @typedef {import('../log/interface.ts').LogService} LogService */
45-
/** @typedef {import("./interface.ts").ErrorHandler} ErrorHandler */
4642
/**
47-
* Provider for `$exceptionHandler` service. Delegates uncaught exceptions to `$log.error()` by default.
48-
* Can be overridden to implement custom error-handling logic.
43+
* Provider for the `$exceptionHandler` service.
44+
*
45+
* The default implementation rethrows exceptions, enabling strict fail-fast behavior.
46+
* Applications may replace the handler via by setting `errorHandler`property or by providing their own
47+
* `$exceptionHandler` factory.
4948
*/
5049
export class ExceptionHandlerProvider {
51-
/** @type {LogService} */
52-
log: LogService;
53-
/** @type {ErrorHandler} */
54-
errorHandler: ErrorHandler;
55-
$get: (string | (($log: LogService) => ErrorHandler))[];
50+
/** @type {ng.ExceptionHandlerService} */
51+
errorHandler: ng.ExceptionHandlerService;
52+
/**
53+
* @returns {ng.ExceptionHandlerService}
54+
*/
55+
$get(): ng.ExceptionHandlerService;
5656
}
57-
export type LogService = import("../log/interface.ts").LogService;
58-
export type ErrorHandler = import("./interface.ts").ErrorHandler;

@types/services/exception/interface.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
* A callback type for handling errors.
33
*
44
* @param exception - The exception associated with the error.
5-
* @param [cause] - Optional information about the context in which the error was thrown.
65
*/
7-
export type ErrorHandler = (exception: Error, cause?: string) => void;
6+
export type ErrorHandler = (exception: Error) => void;

@types/shared/dom.d.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ export function getScope(element: Element): ng.Scope;
106106
* Set scope for a given element.
107107
*
108108
* @param {Element|Node|ChildNode} element - The DOM element to set data on.
109-
* @param {import("../core/scope/scope.js").Scope} scope - The Scope attached to this element
109+
* @param {ng.Scope} scope - The Scope attached to this element
110110
*/
111111
export function setScope(
112112
element: Element | Node | ChildNode,
113-
scope: import("../core/scope/scope.js").Scope,
113+
scope: ng.Scope,
114114
): void;
115115
/**
116116
* Gets isolate scope for a given element.
@@ -123,23 +123,20 @@ export function getIsolateScope(element: Element): any;
123123
* Set isolate scope for a given element.
124124
*
125125
* @param {Element} element - The DOM element to set data on.
126-
* @param {import("../core/scope/scope.js").Scope} scope - The Scope attached to this element
126+
* @param {ng.Scope} scope - The Scope attached to this element
127127
*/
128-
export function setIsolateScope(
129-
element: Element,
130-
scope: import("../core/scope/scope.js").Scope,
131-
): void;
128+
export function setIsolateScope(element: Element, scope: ng.Scope): void;
132129
/**
133130
* Gets the controller instance for a given element, if exists. Defaults to "ngControllerController"
134131
*
135132
* @param {Element} element - The DOM element to get data from.
136133
* @param {string} [name] - Controller name.
137-
* @returns {import("../core/scope/scope.js").Scope|undefined} - The retrieved data
134+
* @returns {ng.Scope|undefined} - The retrieved data
138135
*/
139136
export function getController(
140137
element: Element,
141138
name?: string,
142-
): import("../core/scope/scope.js").Scope | undefined;
139+
): ng.Scope | undefined;
143140
/**
144141
*
145142
* @param {Node} element

0 commit comments

Comments
 (0)