Skip to content

Commit f9d296f

Browse files
authored
Add error info in message 'unable to init db' (fergusstrange#77)
* Add error info in message 'unable to init db'
1 parent 1d2eeea commit f9d296f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

prepare_database.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ func defaultInitDatabase(binaryExtractLocation, runtimePath, pgDataDir, username
4444
postgresInitDBProcess.Stderr = logger
4545
postgresInitDBProcess.Stdout = logger
4646

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

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

5555
return nil

prepare_database_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func Test_defaultInitDatabase_ErrorWhenCannotStartInitDBProcess(t *testing.T) {
4040

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

43-
assert.EqualError(t, err, fmt.Sprintf("unable to init database using: %s/bin/initdb -A password -U Tom -D %s/data --pwfile=%s/pwfile",
43+
assert.NotNil(t, err)
44+
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'",
4445
binTempDir,
4546
runtimeTempDir,
4647
runtimeTempDir))
@@ -61,7 +62,8 @@ func Test_defaultInitDatabase_ErrorInvalidLocaleSetting(t *testing.T) {
6162

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

64-
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",
65+
assert.NotNil(t, err)
66+
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'",
6567
tempDir,
6668
tempDir,
6769
tempDir))

0 commit comments

Comments
 (0)