@@ -106,7 +106,7 @@ const chromePaths = {
106
106
} ,
107
107
} ;
108
108
109
- function getChromePath ( ) : string {
109
+ function getChromePath ( ) {
110
110
const chrome = chromePaths . chrome ;
111
111
112
112
if ( platform && Object . keys ( chrome ) . includes ( platform ) ) {
@@ -115,10 +115,9 @@ function getChromePath(): string {
115
115
return pth ;
116
116
}
117
117
}
118
- throwInvalidPlatformError ( 'Chrome Stable' ) ;
119
118
}
120
119
121
- function getChromeBetaPath ( ) : string {
120
+ function getChromeBetaPath ( ) {
122
121
const beta = chromePaths . beta ;
123
122
124
123
if ( platform && Object . keys ( beta ) . includes ( platform ) ) {
@@ -127,10 +126,9 @@ function getChromeBetaPath(): string {
127
126
return pth ;
128
127
}
129
128
}
130
- throwInvalidPlatformError ( 'Chrome Beta' ) ;
131
129
}
132
130
133
- function getChromeDevPath ( ) : string {
131
+ function getChromeDevPath ( ) {
134
132
const dev = chromePaths . dev ;
135
133
136
134
if ( platform && Object . keys ( dev ) . includes ( platform ) ) {
@@ -139,10 +137,9 @@ function getChromeDevPath(): string {
139
137
return pth ;
140
138
}
141
139
}
142
- throwInvalidPlatformError ( 'Chrome Dev' ) ;
143
140
}
144
141
145
- function getChromeCanaryPath ( ) : string {
142
+ function getChromeCanaryPath ( ) {
146
143
const canary = chromePaths . canary ;
147
144
148
145
if ( platform && Object . keys ( canary ) . includes ( platform ) ) {
@@ -151,61 +148,30 @@ function getChromeCanaryPath(): string {
151
148
return pth ;
152
149
}
153
150
}
154
- throwInvalidPlatformError ( 'Chrome Canary' ) ;
155
151
}
156
152
157
153
export function getAnyChromeStable ( ) : string {
158
- try {
159
- return getChromePath ( ) ;
160
- } catch ( e ) {
161
- throwIfNotChromePathIssue ( e ) ;
154
+ const chrome = getChromePath ( ) ;
155
+ if ( chrome ) {
156
+ return chrome ;
162
157
}
163
158
164
- try {
165
- return getChromeBetaPath ( ) ;
166
- } catch ( e ) {
167
- throwIfNotChromePathIssue ( e ) ;
168
- }
169
-
170
- try {
171
- return getChromeDevPath ( ) ;
172
- } catch ( e ) {
173
- throwIfNotChromePathIssue ( e ) ;
159
+ const beta = getChromeBetaPath ( ) ;
160
+ if ( beta ) {
161
+ return beta ;
174
162
}
175
163
176
- try {
177
- return getChromeCanaryPath ( ) ;
178
- } catch ( e ) {
179
- throwIfNotChromePathIssue ( e ) ;
164
+ const dev = getChromeDevPath ( ) ;
165
+ if ( dev ) {
166
+ return dev ;
180
167
}
181
168
182
- throw {
183
- name : 'chrome-paths' ,
184
- message : `Unable to find any google-chrome-browser.` ,
185
- } ;
186
- }
187
-
188
- function throwInvalidPlatformError (
189
- additionalInfo : string = '' ,
190
- otherDetails ?: any ,
191
- ) : never {
192
- throw {
193
- name : 'chrome-paths' ,
194
- message : `Couldn't find the chrome browser. ${ additionalInfo } ` ,
195
- additionalInfo,
196
- otherDetails,
197
- } ;
198
- }
199
-
200
- function throwIfNotChromePathIssue ( obj : any ) {
201
- if (
202
- Object . prototype . toString . call ( obj ) === '[object Object]' &&
203
- obj &&
204
- obj . name &&
205
- obj . name === 'chrome-paths'
206
- ) {
207
- return ;
169
+ const canary = getChromeCanaryPath ( ) ;
170
+ if ( canary ) {
171
+ return canary ;
208
172
}
209
173
210
- throw obj ;
174
+ const error = new Error ( 'Unable to find any google-chrome-browser.' ) ;
175
+ error . name = 'ChromePathsError' ;
176
+ throw error ;
211
177
}
0 commit comments