Missing some exception information from process execution
IsakSIT opened this issue · 1 comments
Hi, I have recently started using this lib and think it's really convenient feature to have available.
I have a question regarding the exception handling for processes.
So I did a simple test like this to generate an exception.
EmbeddedPostgres.builder().setDataDirectory(".").setPort(5432).start()
This will generate an exception
INFO io.zonky.test.db.postgres.embedded.EmbeddedPostgres Postgres binaries at /var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac
INFO io.zonky.test.db.postgres.embedded.EmbeddedPostgres The files belonging to this database system will be owned by user "some_user".
ERROR java.lang.IllegalStateException: Process [/var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac/bin/initdb, -A, trust, -U, postgres, -D, ., -E, UTF-8] failed
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.system(EmbeddedPostgres.java:624)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.initdb(EmbeddedPostgres.java:243)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres.<init>(EmbeddedPostgres.java:156)
at io.zonky.test.db.postgres.embedded.EmbeddedPostgres$Builder.start(EmbeddedPostgres.java:577)
So now I know it failed somewhere and which process but no reason as to why?
If I execute this in my terminal instead it will return
/var/folders/yx/zq_6p5_j5tqf5fpfgbbfp_qjjc037p/T/embedded-pg/PG-d7f5f3cbfd0f44a07a6d0c5fb002a4ac/bin/initdb -A trust -U postgres -D . -E UTF-8
The files belonging to this database system will be owned by user "some_user".
This user must also own the server process.
The database cluster will be initialized with locales
COLLATE: C
CTYPE: UTF-8
MESSAGES: C
MONETARY: C
NUMERIC: C
TIME: C
initdb: could not find suitable text search configuration for locale "UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
initdb: directory "." exists but is not empty
If you want to create a new database system, either remove or empty
the directory "." or run initdb
with an argument other than ".".
So then simply setting ./temp
as a new data directory will solve my problem
EmbeddedPostgres.builder().setDataDirectory("./temp").setPort(5432).start()
However, this wasn't something I knew/realised until I saw the error message I got when running it in terminal.
I was wondering why I can't see this information when I run the EmbeddedPostgres? Or maybe there is a way already?
Side note/question
Isn't this line supposed to print something after ...failed"?
throw new IllegalStateException(String.format("Process %s failed%n%s", Arrays.asList(command), IOUtils.toString(process.getErrorStream())));
Hi, thanks for the report. You're right, logging doesn't work correctly.
The root cause is that ProcessOutputLogger
stops logging immediately after the process is finished, even though there is still some data buffered in the output stream.
Also, calling process.getErrorStream()
returns no output because ProcessBuilder#redirectErrorStream
property is set to true, so all error information is redirected to standard output.