FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: OnDiscardedError typings and event (#6777) · NativeScript/NativeScript@28db2af · GitHub

Commit 28db2af

Browse files
authored
feat: OnDiscardedError typings and event (#6777)
* feat: OnDiscardedError typings and event * remove ios and android from DiscardedErrorEventData
1 parent 4cda0e7 commit 28db2af

5 files changed

Lines changed: 47 additions & 10 deletions

File tree

‎apps/app/ui-tests-app/app.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ application.on(application.uncaughtErrorEvent, function(args: application.Unhand
8181
console.log("### stack: " + args.error.stack);
8282
});
8383

84+
application.on(application.discardedErrorEvent, function(args: application.DiscardedErrorEventData) {
85+
console.log("### [Discarded] NativeScriptError: " + args.error);
86+
console.log("### [Discarded] nativeException: " + (<any>args.error).nativeException);
87+
console.log("### [Discarded] stackTrace: " + (<any>args.error).stackTrace);
88+
console.log("### [Discarded] stack: " + args.error.stack);
89+
});
90+
8491
application.setCssFileName("ui-tests-app/app.css");
8592

8693
application.start({ moduleName: "ui-tests-app/main-page" });

‎tests/app/app/app.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ application.on(application.uncaughtErrorEvent, function (args: application.Unhan
9090
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
9191
});
9292

93+
application.on(application.discardedErrorEvent, function (args: application.DiscardedErrorEventData) {
94+
console.log("[Discarded] NativeScriptError: " + args.error);
95+
console.log((<any>args.error).nativeException || (<any>args.error).nativeError);
96+
console.log((<any>args.error).stackTrace || (<any>args.error).stack);
97+
});
98+
9399
// Android activity events
94100
if (application.android) {
95101
application.android.on(application.AndroidApplication.activityCreatedEvent, function (args: application.AndroidActivityBundleEventData) {

‎tns-core-modules/application/application-common.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ import {
3838
getRootView,
3939
iOSApplication,
4040
LoadAppCSSEventData,
41-
UnhandledErrorEventData
41+
UnhandledErrorEventData,
42+
DiscardedErrorEventData
4243
} from "./application";
4344

44-
export { UnhandledErrorEventData, CssChangedEventData, LoadAppCSSEventData };
45+
export { UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData };
4546

4647
export const launchEvent = "launch";
4748
export const suspendEvent = "suspend";
@@ -50,6 +51,7 @@ export const resumeEvent = "resume";
5051
export const exitEvent = "exit";
5152
export const lowMemoryEvent = "lowMemory";
5253
export const uncaughtErrorEvent = "uncaughtError";
54+
export const discardedErrorEvent = "discardedError";
5355
export const orientationChangedEvent = "orientationChanged";
5456

5557
let cssFile: string = "./app.css";
@@ -122,3 +124,7 @@ export function addCss(cssText: string): void {
122124
global.__onUncaughtError = function (error: NativeScriptError) {
123125
events.notify(<UnhandledErrorEventData>{ eventName: uncaughtErrorEvent, object: app, android: error, ios: error, error: error });
124126
}
127+
128+
global.__onDiscardedError = function (error: NativeScriptError) {
129+
events.notify(<DiscardedErrorEventData>{ eventName: discardedErrorEvent, object: app, error: error });
130+
}

‎tns-core-modules/application/application.d.ts‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export var displayedEvent: string;
2121
*/
2222
export var uncaughtErrorEvent: string;
2323

24+
/**
25+
* String value used when hooking to discardedError event.
26+
*/
27+
export var discardedErrorEvent: string;
28+
2429
/**
2530
* String value used when hooking to suspend event.
2631
*/
@@ -103,6 +108,13 @@ export interface UnhandledErrorEventData extends ApplicationEventData {
103108
error: NativeScriptError;
104109
}
105110

111+
/**
112+
* Event data containing information about discarded application errors.
113+
*/
114+
export interface DiscardedErrorEventData extends ApplicationEventData {
115+
error: NativeScriptError;
116+
}
117+
106118
/**
107119
* Event data containing information about application css change.
108120
*/
@@ -137,7 +149,7 @@ export function setResources(res: any): void;
137149
export function setResources(resources: any);
138150

139151
/**
140-
* Sets css file name for the application.
152+
* Sets css file name for the application.
141153
*/
142154
export function setCssFileName(cssFile: string): void;
143155

@@ -199,7 +211,7 @@ export function shouldCreateRootFrame(): boolean;
199211

200212
/**
201213
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
202-
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
214+
* @param eventNames - String corresponding to events (e.g. "onLaunch"). Optionally could be used more events separated by `,` (e.g. "onLaunch", "onSuspend").
203215
* @param callback - Callback function which will be executed when event is raised.
204216
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
205217
*/
@@ -262,6 +274,11 @@ export function on(event: "lowMemory", callback: (args: ApplicationEventData) =>
262274
*/
263275
export function on(event: "uncaughtError", callback: (args: UnhandledErrorEventData) => void, thisArg?: any);
264276

277+
/**
278+
* This event is raised when an discarded error occurs while the application is running.
279+
*/
280+
export function on(event: "discardedError", callback: (args: DiscardedErrorEventData) => void, thisArg?: any);
281+
265282
/**
266283
* This event is raised the orientation of the current device has changed.
267284
*/
@@ -403,13 +420,13 @@ export class AndroidApplication extends Observable {
403420
/**
404421
* Initialized the android-specific application object with the native android.app.Application instance.
405422
* This is useful when creating custom application types.
406-
* @param nativeApp - the android.app.Application instance that started the app.
423+
* @param nativeApp - the android.app.Application instance that started the app.
407424
*/
408425
init: (nativeApp) => void;
409426

410427
/**
411428
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
412-
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
429+
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
413430
* @param callback - Callback function which will be executed when event is raised.
414431
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
415432
*/
@@ -516,15 +533,15 @@ export class AndroidApplication extends Observable {
516533
public static activityRequestPermissionsEvent: string;
517534

518535
/**
519-
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
536+
* Register a BroadcastReceiver to be run in the main activity thread. The receiver will be called with any broadcast Intent that matches filter, in the main application thread.
520537
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#registerReceiver%28android.content.BroadcastReceiver,%20android.content.IntentFilter%29'
521538
* @param intentFilter A string containing the intent filter.
522539
* @param onReceiveCallback A callback function that will be called each time the receiver receives a broadcast.
523540
*/
524541
registerBroadcastReceiver(intentFilter: string, onReceiveCallback: (context: any /* android.content.Context */, intent: any /* android.content.Intent */) => void): void;
525542

526543
/**
527-
* Unregister a previously registered BroadcastReceiver.
544+
* Unregister a previously registered BroadcastReceiver.
528545
* For more information, please visit 'http://developer.android.com/reference/android/content/Context.html#unregisterReceiver(android.content.BroadcastReceiver)'
529546
* @param intentFilter A string containing the intent filter with which the receiver was originally registered.
530547
*/

‎tns-core-modules/module.d.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare var global: NodeJS.Global;
33
interface ModuleResolver {
44
/**
55
* A function used to resolve the exports for a module.
6-
* @param uri The name of the module to be resolved.
6+
* @param uri The name of the module to be resolved.
77
*/
88
(uri: string): any;
99
}
@@ -18,7 +18,7 @@ declare namespace NodeJS {
1818
* Register all modules from a webpack context.
1919
* The context is one created using the following webpack utility:
2020
* https://webpack.github.io/docs/context.html
21-
*
21+
*
2222
* The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.),
2323
* while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as:
2424
* ```
@@ -54,6 +54,7 @@ declare namespace NodeJS {
5454
__onLiveSync: (context?: { type: string, module: string }) => void;
5555
__onLiveSyncCore: () => void;
5656
__onUncaughtError: (error: NativeScriptError) => void;
57+
__onDiscardedError: (error: NativeScriptError) => void;
5758
TNS_WEBPACK?: boolean;
5859
__requireOverride?: (name: string, dir: string) => any;
5960
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL