6
6
*/
7
7
8
8
/* @flow */
9
- import { listenToRuntimeErrors } from './listenToRuntimeErrors' ;
9
+ import {
10
+ listenToRuntimeErrors ,
11
+ crashWithFrames ,
12
+ } from './listenToRuntimeErrors' ;
10
13
import { iframeStyle } from './styles' ;
11
14
import { applyStyles } from './utils/dom/css' ;
12
15
@@ -47,6 +50,14 @@ export function reportBuildError(error: string) {
47
50
update ( ) ;
48
51
}
49
52
53
+ export function reportRuntimeError (
54
+ error : Error ,
55
+ options ?: RuntimeReportingOption = { }
56
+ ) {
57
+ currentRuntimeErrorOptions = options ;
58
+ crashWithFrames ( handleRuntimeError ( options ) ) ( error ) ;
59
+ }
60
+
50
61
export function dismissBuildError ( ) {
51
62
currentBuildError = null ;
52
63
update ( ) ;
@@ -64,28 +75,35 @@ export function startReportingRuntimeErrors(options: RuntimeReportingOptions) {
64
75
) ;
65
76
}
66
77
currentRuntimeErrorOptions = options ;
67
- stopListeningToRuntimeErrors = listenToRuntimeErrors ( errorRecord => {
68
- try {
69
- if ( typeof options . onError === 'function' ) {
70
- options . onError . call ( null ) ;
71
- }
72
- } finally {
73
- handleRuntimeError ( errorRecord ) ;
74
- }
75
- } , options . filename ) ;
78
+ stopListeningToRuntimeErrors = listenToRuntimeErrors (
79
+ handleRuntimeError ( options ) ,
80
+ options . filename
81
+ ) ;
76
82
}
77
83
78
- function handleRuntimeError ( errorRecord ) {
79
- if (
80
- currentRuntimeErrorRecords . some ( ( { error } ) => error === errorRecord . error )
81
- ) {
82
- // Deduplicate identical errors.
83
- // This fixes https://github.com/facebook/create-react-app/issues/3011.
84
- return ;
84
+ const handleRuntimeError = ( options : RuntimeReportingOptions ) => (
85
+ errorRecord : ErrorRecord
86
+ ) => {
87
+ try {
88
+ if ( typeof options . onError === 'function' ) {
89
+ options . onError . call ( null ) ;
90
+ }
91
+ } finally {
92
+ if (
93
+ currentRuntimeErrorRecords . some (
94
+ ( { error } ) => error === errorRecord . error
95
+ )
96
+ ) {
97
+ // Deduplicate identical errors.
98
+ // This fixes https://github.com/facebook/create-react-app/issues/3011.
99
+ return ;
100
+ }
101
+ currentRuntimeErrorRecords = currentRuntimeErrorRecords . concat ( [
102
+ errorRecord ,
103
+ ] ) ;
104
+ update ( ) ;
85
105
}
86
- currentRuntimeErrorRecords = currentRuntimeErrorRecords . concat ( [ errorRecord ] ) ;
87
- update ( ) ;
88
- }
106
+ } ;
89
107
90
108
export function dismissRuntimeErrors ( ) {
91
109
currentRuntimeErrorRecords = [ ] ;
0 commit comments