Open joethorley opened 1 year ago
Do you still get this error? I get errors on some other tests but not this one on my machine
Yeah I'm still getting the error
Error (test-pg.R:6:3): test sbf_open_pg works
<Rcpp::exception/C++Error/error/condition>
Error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
Backtrace:
▆
1. └─subfoldr2::sbf_open_pg(config_path = NULL, config_value = "default") at test-pg.R:6:2
2. └─psql::psql_connect(config_path = config_path, config_value = config_value) at subfoldr2/R/pg.R:24:2
3. ├─DBI::dbConnect(...)
4. └─DBI::dbConnect(...)
5. └─RPostgres (local) .local(drv, ...)
6. └─RPostgres:::connection_create(names(opts), as.vector(opts), check_interrupts)
7. ```
And this is with the fix-test-errors
branch
Ok, yea I didn't change anything on this test in that branch as I am not getting the error. I'll dig into the code and see what you need to have this function work. I am thinking you are missing some type of installation or initiation step for PostgreSQL
In the terminal can you try these commands and let me know if they work:
psql --version
psql
This is the outputs you should get if the commands work.
➜ ~ psql --version
psql (PostgreSQL) 14.8 (Homebrew)
➜ ~ psql
psql (14.8 (Homebrew))
Type "help" for help.
aylapearson=#
❯ psql --version
psql (PostgreSQL) 14.8 (Homebrew)
psql
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
I am not sure the checks, error handling or skipping to add in.
The tests do have the skip_on_ci()
as setting up and installing PostgreSQL in the action would be slow and potentially error prone.
In this case you have psql installed so I could create a check for that but it would pass in this case. We would want to add that to the psql
package as the subfoldr2
functions are a wrapper to that package. In that case we could add this check to each of the psql
functions, it's in one of the functions but not the other ones.
software_test <- try(system2("psql", "--version", stdout = TRUE))
if (inherits(software_test, "try-error")) {
stop(
"You must have `psql` downloaded before proceeding.
Go to https://www.postgresql.org/download/ for instructions.",
call. = FALSE
)
}
In terms of checking that someone has the correct default database set up I am not sure how to check that as we are starting to get into the connection phase and if we try that before doing the connection if it works then you are stuck in the terminal as it will connect. Since it is based on the computer user name there isn't a static thing to check. We can do terminal commands to list what db's they have present but since this could vary a lot I am not sure what is good to check in this case.
➜ ~ psql -lqt | cut -d \| -f 1
aylapearson
postgres
template0
template1
@joethorley I was just getting these errors too.
Try following the steps here https://poisson-data-analysis.netlify.app/postgresql-guide#basics-of-using-postgresql
to get your default db set up.
I had further issues with my RStudio terminal not having the right PATH (i.e., it couldn't find psql because it was missing homebrew from the PATH), which we solved by adding a .zprofile
file, (added by running touch ~/.zprofile
in the terminal) with this inside: eval "$(/opt/homebrew/bin/brew shellenv)".
@nehill197 - thanks this is great information!