@@ -6498,28 +6498,34 @@ pseudo1D <- function(x){range(x)[which.max(abs(range(x)))]}
6498
6498
# return(invisible(usrList))
6499
6499
# }
6500
6500
#######################################################################################
6501
- handleFoErrors <- function(cond, fileName = NULL) {
6501
+ handleFoErrors <- function(cond, fileName = NULL, logFile = "fo_error_log.txt" ) {
6502
6502
# Set errors flag to TRUE to indicate that an error occurred
6503
6503
errors <<- TRUE
6504
6504
6505
+ # Get the current timestamp
6506
+ timestamp <- Sys.time()
6507
+
6505
6508
# Customize the error message based on the error type or condition
6506
- if (grepl("unused argument \\(cond\\)", cond$message)) {
6507
- log_message <- "An unused argument error occurred in the function. Please check the function arguments."
6508
- } else if (grepl("truncating string with embedded nuls", cond$message)) {
6509
- # Specific handling for "truncating string with embedded nuls" warnings/errors
6510
- log_message <- paste("Warning: A truncation error occurred due to embedded null characters in the file:",
6511
- if (!is.null(fileName)) basename(fileName) else "", sep = " ")
6509
+ if (grepl("truncating string with embedded nuls", cond$message)) {
6510
+ # Suppress "truncating string with embedded nuls" warnings
6511
+ log_message <- paste0("[", timestamp, "] Warning: A truncation issue occurred due to embedded null characters in the file: ",
6512
+ if (!is.null(fileName)) basename(fileName) else "")
6513
+ # Return NULL but suppress further output for these specific warnings
6514
+ return(NULL)
6515
+ } else if (grepl("unused argument \\(cond\\)", cond$message)) {
6516
+ log_message <- paste0("[", timestamp, "] An unused argument error occurred. Please check the function arguments.")
6512
6517
} else {
6513
6518
# Generic error handling for other types of errors
6514
- log_message <- paste("An error occurred while processing", if (!is.null(fileName)) basename(fileName) else "", ":", cond$message)
6519
+ log_message <- paste0("[", timestamp, "] An error occurred while processing ",
6520
+ if (!is.null(fileName)) basename(fileName) else "", ": ", cond$message)
6515
6521
}
6516
-
6517
- # Log the error message to a log file or suppress the output
6518
- write(log_message, file = "fo_error_log.txt" , append = TRUE)
6519
-
6522
+
6523
+ # Log the error message to the log file
6524
+ write(log_message, file = logFile , append = TRUE)
6525
+
6520
6526
# Optionally print the message for debugging purposes (comment out to suppress completely)
6521
6527
cat(log_message, "\n")
6522
-
6528
+
6523
6529
# Return NULL or an appropriate value to allow the function to continue
6524
6530
return(NULL)
6525
6531
}
@@ -6635,7 +6641,7 @@ file_open <- function(fileName, ...){
6635
6641
}
6636
6642
6637
6643
## Tell user which files have been loaded
6638
- log_message(basename(usrList[i]), quote = FALSE)
6644
+ # log_message(basename(usrList[i]), quote = FALSE)
6639
6645
flush.console()
6640
6646
}
6641
6647
@@ -6644,8 +6650,7 @@ file_open <- function(fileName, ...){
6644
6650
myAssign("currentSpectrum", currentSpectrum, save.backup = FALSE)
6645
6651
6646
6652
## Refresh the splash screen after the files are loaded and currentSpectrum is set
6647
- if (!is.null(fileFolder) && length(fileFolder) > 0) {
6648
- log_message("Refreshing splash screen with current spectrum.")
6653
+ if (!is.null(fileFolder) && length(fileFolder) > 0) {
6649
6654
6650
6655
## Ensure the graphical device is ready and refresh splash screen
6651
6656
if (dev.cur() == 1) {
@@ -6655,13 +6660,13 @@ file_open <- function(fileName, ...){
6655
6660
splashScreen() # Call the splash screen
6656
6661
6657
6662
## Short delay to ensure screen is ready
6658
- Sys.sleep(0.5)
6663
+ # Sys.sleep(0.5)
6659
6664
6660
6665
## Force a redraw of the graphics device
6661
6666
dev.flush()
6662
6667
refresh(...)
6663
- }
6664
-
6668
+ }
6669
+
6665
6670
## Display error dialog if errors occurred
6666
6671
if (errors) {
6667
6672
myMsg(paste('Errors occurred while opening files. Check the R console for details.', sep = '\n'), icon = 'error')
0 commit comments