@@ -267,7 +267,7 @@ REBINT Mode_Syms[] = {
267
267
268
268
/***********************************************************************
269
269
**
270
- */ static void Read_File_Port (REBSER * port , REBREQ * file , REBVAL * path , REBCNT args , REBCNT len )
270
+ */ static void Read_File_Port (REBREQ * file , REBVAL * path , REBCNT args , REBCNT len )
271
271
/*
272
272
** Read from a file port.
273
273
**
@@ -283,7 +283,11 @@ REBINT Mode_Syms[] = {
283
283
// Do the read, check for errors:
284
284
file -> data = BIN_HEAD (ser );
285
285
file -> length = len ;
286
- if (OS_DO_DEVICE (file , RDC_READ ) < 0 ) Trap_Port (RE_READ_ERROR , port , file -> error );
286
+ if (OS_DO_DEVICE (file , RDC_READ ) < 0 ) return ; // Trap_Port(RE_READ_ERROR, port, file->error);
287
+ // Not throwing the error from here!
288
+ // We may want to close the port before error reporting.
289
+ // It is passed above in the file->error
290
+
287
291
SERIES_TAIL (ser ) = file -> actual ;
288
292
STR_TERM (ser );
289
293
@@ -351,7 +355,9 @@ REBINT Mode_Syms[] = {
351
355
//Trap1(PE_BAD_ARGUMENT, data);
352
356
}
353
357
file -> length = len ;
354
- OS_DO_DEVICE (file , RDC_WRITE );
358
+ OS_DO_DEVICE (file , RDC_WRITE ); // don't report error here!
359
+ // We may want to close the port before error reporting.
360
+ // It is passed above in the file->error
355
361
356
362
if (n > 0 ) {
357
363
// remove the temporary added newline from the series
@@ -427,7 +433,7 @@ REBINT Mode_Syms[] = {
427
433
REBREQ * file = 0 ;
428
434
REBCNT args = 0 ;
429
435
REBCNT len ;
430
- REBINT result ;
436
+ REBINT result , error ;
431
437
REBOOL opened = FALSE; // had to be opened (shortcut case)
432
438
433
439
//Print("FILE ACTION: %r", Get_Action_Word(action));
@@ -464,14 +470,15 @@ REBINT Mode_Syms[] = {
464
470
465
471
if (args & AM_READ_SEEK ) Set_Seek (file , D_ARG (ARG_READ_INDEX ));
466
472
len = Set_Length (ds , file , ARG_READ_PART );
467
- Read_File_Port (port , file , path , args , len );
473
+ Read_File_Port (file , path , args , len );
468
474
475
+ error = (REBINT )file -> error ; // store error value, before closing the file!
469
476
if (opened ) {
470
477
OS_DO_DEVICE (file , RDC_CLOSE );
471
478
Cleanup_File (file );
472
479
}
473
480
474
- if (file -> error ) Trap_Port (RE_READ_ERROR , port , file -> error );
481
+ if (error ) Trap_Port (RE_READ_ERROR , port , error );
475
482
break ;
476
483
477
484
case A_APPEND :
@@ -522,12 +529,14 @@ REBINT Mode_Syms[] = {
522
529
Write_File_Port (file , spec , len , args );
523
530
524
531
file -> file .index += file -> actual ;
532
+
533
+ error = (REBINT )file -> error ; // store error value, before closing the file!
525
534
if (opened ) {
526
535
OS_DO_DEVICE (file , RDC_CLOSE );
527
536
Cleanup_File (file );
528
537
}
529
538
530
- if (file -> error ) Trap1 (RE_WRITE_ERROR , path );
539
+ if (error ) Trap_Port (RE_WRITE_ERROR , port , error );
531
540
* D_RET = * path ;
532
541
break ;
533
542
@@ -542,7 +551,7 @@ REBINT Mode_Syms[] = {
542
551
case A_COPY :
543
552
if (!IS_OPEN (file )) Trap1 (RE_NOT_OPEN , path ); //!!!! wrong msg
544
553
len = Set_Length (ds , file , 2 );
545
- Read_File_Port (port , file , path , args , len );
554
+ Read_File_Port (file , path , args , len );
546
555
break ;
547
556
548
557
case A_OPENQ :
0 commit comments