Skip to content

Add error info in message 'unable to init db' #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions prepare_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func defaultInitDatabase(binaryExtractLocation, runtimePath, pgDataDir, username
postgresInitDBProcess.Stderr = logger
postgresInitDBProcess.Stdout = logger

if err := postgresInitDBProcess.Run(); err != nil {
return fmt.Errorf("unable to init database using: %s", postgresInitDBProcess.String())
if err = postgresInitDBProcess.Run(); err != nil {
return fmt.Errorf("unable to init database using '%s': %w", postgresInitDBProcess.String(), err)
}

if err = os.Remove(passwordFile); err != nil {
return fmt.Errorf("unable to remove password file '%v': %v", passwordFile, err)
return fmt.Errorf("unable to remove password file '%v': %w", passwordFile, err)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions prepare_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func Test_defaultInitDatabase_ErrorWhenCannotStartInitDBProcess(t *testing.T) {

err = defaultInitDatabase(binTempDir, runtimeTempDir, filepath.Join(runtimeTempDir, "data"), "Tom", "Beer", "", os.Stderr)

assert.EqualError(t, err, fmt.Sprintf("unable to init database using: %s/bin/initdb -A password -U Tom -D %s/data --pwfile=%s/pwfile",
assert.NotNil(t, err)
assert.Contains(t, err.Error(), fmt.Sprintf("unable to init database using '%s/bin/initdb -A password -U Tom -D %s/data --pwfile=%s/pwfile'",
binTempDir,
runtimeTempDir,
runtimeTempDir))
Expand All @@ -61,7 +62,8 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) {

err = defaultInitDatabase(tempDir, tempDir, filepath.Join(tempDir, "data"), "postgres", "postgres", "en_XY", os.Stderr)

assert.EqualError(t, err, fmt.Sprintf("unable to init database using: %s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --locale=en_XY",
assert.NotNil(t, err)
assert.Contains(t, err.Error(), fmt.Sprintf("unable to init database using '%s/bin/initdb -A password -U postgres -D %s/data --pwfile=%s/pwfile --locale=en_XY'",
tempDir,
tempDir,
tempDir))
Expand Down