@@ -224,28 +224,40 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
224
224
225
225
write ( path : Path , content : virtualFs . FileBuffer ) : Observable < void > {
226
226
return new Observable ( obs => {
227
- // Create folders if necessary.
228
- const _createDir = ( path : Path ) => {
229
- if ( fs . existsSync ( getSystemPath ( path ) ) ) {
230
- return ;
231
- }
227
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
228
+ // fixed.
229
+ try {
230
+ // Create folders if necessary.
231
+ const _createDir = ( path : Path ) => {
232
+ if ( fs . existsSync ( getSystemPath ( path ) ) ) {
233
+ return ;
234
+ }
235
+ _createDir ( dirname ( path ) ) ;
236
+ fs . mkdirSync ( getSystemPath ( path ) ) ;
237
+ } ;
232
238
_createDir ( dirname ( path ) ) ;
233
- fs . mkdirSync ( getSystemPath ( path ) ) ;
234
- } ;
235
- _createDir ( dirname ( path ) ) ;
236
- fs . writeFileSync ( getSystemPath ( path ) , new Uint8Array ( content ) ) ;
239
+ fs . writeFileSync ( getSystemPath ( path ) , new Uint8Array ( content ) ) ;
237
240
238
- obs . next ( ) ;
239
- obs . complete ( ) ;
241
+ obs . next ( ) ;
242
+ obs . complete ( ) ;
243
+ } catch ( err ) {
244
+ obs . error ( err ) ;
245
+ }
240
246
} ) ;
241
247
}
242
248
243
249
read ( path : Path ) : Observable < virtualFs . FileBuffer > {
244
250
return new Observable ( obs => {
245
- const buffer = fs . readFileSync ( getSystemPath ( path ) ) ;
251
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
252
+ // fixed.
253
+ try {
254
+ const buffer = fs . readFileSync ( getSystemPath ( path ) ) ;
246
255
247
- obs . next ( new Uint8Array ( buffer ) . buffer as virtualFs . FileBuffer ) ;
248
- obs . complete ( ) ;
256
+ obs . next ( new Uint8Array ( buffer ) . buffer as virtualFs . FileBuffer ) ;
257
+ obs . complete ( ) ;
258
+ } catch ( err ) {
259
+ obs . error ( err ) ;
260
+ }
249
261
} ) ;
250
262
}
251
263
@@ -277,24 +289,42 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
277
289
278
290
rename ( from : Path , to : Path ) : Observable < void > {
279
291
return new Observable ( obs => {
280
- fs . renameSync ( getSystemPath ( from ) , getSystemPath ( to ) ) ;
281
- obs . next ( ) ;
282
- obs . complete ( ) ;
292
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
293
+ // fixed.
294
+ try {
295
+ fs . renameSync ( getSystemPath ( from ) , getSystemPath ( to ) ) ;
296
+ obs . next ( ) ;
297
+ obs . complete ( ) ;
298
+ } catch ( err ) {
299
+ obs . error ( err ) ;
300
+ }
283
301
} ) ;
284
302
}
285
303
286
304
list ( path : Path ) : Observable < PathFragment [ ] > {
287
305
return new Observable ( obs => {
288
- const names = fs . readdirSync ( getSystemPath ( path ) ) ;
289
- obs . next ( names . map ( name => fragment ( name ) ) ) ;
290
- obs . complete ( ) ;
306
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
307
+ // fixed.
308
+ try {
309
+ const names = fs . readdirSync ( getSystemPath ( path ) ) ;
310
+ obs . next ( names . map ( name => fragment ( name ) ) ) ;
311
+ obs . complete ( ) ;
312
+ } catch ( err ) {
313
+ obs . error ( err ) ;
314
+ }
291
315
} ) ;
292
316
}
293
317
294
318
exists ( path : Path ) : Observable < boolean > {
295
319
return new Observable ( obs => {
296
- obs . next ( fs . existsSync ( getSystemPath ( path ) ) ) ;
297
- obs . complete ( ) ;
320
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
321
+ // fixed.
322
+ try {
323
+ obs . next ( fs . existsSync ( getSystemPath ( path ) ) ) ;
324
+ obs . complete ( ) ;
325
+ } catch ( err ) {
326
+ obs . error ( err ) ;
327
+ }
298
328
} ) ;
299
329
}
300
330
@@ -310,8 +340,14 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
310
340
// Some hosts may not support stat.
311
341
stat ( path : Path ) : Observable < virtualFs . Stats < fs . Stats > > {
312
342
return new Observable ( obs => {
313
- obs . next ( fs . statSync ( getSystemPath ( path ) ) ) ;
314
- obs . complete ( ) ;
343
+ // TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
344
+ // fixed.
345
+ try {
346
+ obs . next ( fs . statSync ( getSystemPath ( path ) ) ) ;
347
+ obs . complete ( ) ;
348
+ } catch ( err ) {
349
+ obs . error ( err ) ;
350
+ }
315
351
} ) ;
316
352
}
317
353
0 commit comments