You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add error handling for gzipped file decompression and external command failures in fread() (#7097)
* improve error handling in fread() for cmd exe and decompression
* trailing ws
* added tests
* Update test no.
* more crptd file in 2nd test
* improved error mssg in 2nd test
* enhance test 2
* explained meaning of these numbers
* wrng instead of error in test 2
* also catch warning; clean-up
* windows-only warning
---------
Co-authored-by: Michael Chirico <[email protected]>
stopf("External command failed with exit code %d. This can happen when the disk is full in the temporary directory ('%s'). See ?fread for the tmpdir argument.", status, tmpdir)
stopf("To read %s files directly, fread() requires 'R.utils' package which cannot be found. Please install 'R.utils' using 'install.packages('R.utils')'.", if (w<=2L||gzsig) "gz"else"bz2") # nocov
118
122
FUN=if (w<=2L||gzsig) gzfileelsebzfile
119
-
R.utils::decompressFile(file, decompFile<-tempfile(tmpdir=tmpdir), ext=NULL, FUN=FUN, remove=FALSE) # ext is not used by decompressFile when destname is supplied, but isn't optional
120
-
file=decompFile# don't use 'tmpFile' symbol again, as tmpFile might be the http://domain.org/file.csv.gz download
123
+
decompFile= tempfile(tmpdir=tmpdir)
121
124
on.exit(unlink(decompFile), add=TRUE)
125
+
tryCatch({
126
+
R.utils::decompressFile(file, decompFile, ext=NULL, FUN=FUN, remove=FALSE) # ext is not used by decompressFile when destname is supplied, but isn't optional
127
+
}, error=function(e) {
128
+
stopf("R.utils::decompressFile failed to decompress file '%s':\n %s\n. This can happen when the disk is full in the temporary directory ('%s'). See ?fread for the tmpdir argument.", file, conditionMessage(e), tmpdir)
129
+
})
130
+
file=decompFile# don't use 'tmpFile' symbol again, as tmpFile might be the http://domain.org/file.csv.gz download
122
131
}
123
132
file= enc2native(file) # CfreadR cannot handle UTF-8 if that is not the native encoding, see #3078.
0 commit comments