Closed mkoohafkan closed 2 years ago
The ...
argument is provided to for this purpose. If you name the arguments, they are passed through to system2
. stdout
and stderr
can be captured in a file or as a character vector which you could use for error handling in your wrapper function.
That only works if the user provides file paths to write stderr
and stdout
to. There is currently no way to capture the output as a character vector, which both system2()
and processx::run()
support. Reading and parsing files to determine error codes is suboptimal.
The solution might be as simple as assigning the result of the system2()
call to a variable and return()
ing that variable at the end; if bcp
is well-behaved the call should return 0
if it succeeded and some other value if it did not. This should also be compatible with the maxerrors
argument, i.e., hopefully the system2()
call will return 0
even if bcp
errors, provided the total number of errors is below maxerrors
.
So the issue is that maxerrors
returns a system2()
error which stops the function but if maxerrors
is not reached then it continues on silently? Wouldn't setting maxerrors
to 0 fail fast and allow you to use tryCatch
to find what failed?
No, my statement regarding maxerrors
was speculation. The issue is that errors from bcp
are not returned by bcpImport
without writing and parsing files passed as stdout
/stderr
arguments . The only way bcpImport
can return an error directly is if the system2()
call is malformed or something goes wrong with any of the dbExecute
calls. If bcpImport
could return the integer result of the system2()
call (rather than nothing, as is the current implementation) that might be sufficient to identify if bcp
succeeded. I can test that but I won't be able to do so until Monday or Tuesday.
005b9a6ec88209c97f689ff7af69312f4df3751f
This will be in the next release. The output of bcpImport
now mimics the output of running system2('bcp'...)
.
Sometimes
bcp
can fail, but in the current designbcpImport()
will only throw an error if thesystem2()
call is malformed. Ifbcp
runs but fails for any other reason, there is no way to tell asbcpImport()
does not return any value and there is no checking of either the code returned bysystem2()
or examining the output. There are ways to capture the output ofsystem2()
via thestdout
andstderr
arguments, and theprocessx
package provides an enhanced version ofsystem2()
that may be easier to work with.For example, bcp was writing
but because I am calling it from a function, inside a larger routine, I never saw that output until I started noticing a bunch of zero-row tables and reran the commands manually.