Skip to content

Commit 90170db

Browse files
committed
return error in Config.FormatDSN
Not all configs may be representable by a DSN string in the future, e.g. #771 Updates #771.
1 parent b66d043 commit 90170db

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

dsn.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (cfg *Config) normalize() error {
150150

151151
// FormatDSN formats the given Config into a DSN string which can be passed to
152152
// the driver.
153-
func (cfg *Config) FormatDSN() string {
153+
func (cfg *Config) FormatDSN() (dsn string, err error) {
154154
var buf bytes.Buffer
155155

156156
// [username[:password]@]
@@ -368,7 +368,7 @@ func (cfg *Config) FormatDSN() string {
368368
}
369369
}
370370

371-
return buf.String()
371+
return buf.String(), nil
372372
}
373373

374374
// ParseDSN parses the DSN string to a Config

dsn_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestDSNReformat(t *testing.T) {
120120
cfg1.tls = nil // pointer not static
121121
res1 := fmt.Sprintf("%+v", cfg1)
122122

123-
dsn2 := cfg1.FormatDSN()
123+
dsn2, _ := cfg1.FormatDSN()
124124
cfg2, err := ParseDSN(dsn2)
125125
if err != nil {
126126
t.Error(err.Error())
@@ -312,7 +312,7 @@ func TestParamsAreSorted(t *testing.T) {
312312
"quux": "loo",
313313
"foobar": "baz",
314314
}
315-
actual := cfg.FormatDSN()
315+
actual, _ := cfg.FormatDSN()
316316
if actual != expected {
317317
t.Errorf("generic Config.Params were not sorted: want %#v, got %#v", expected, actual)
318318
}

0 commit comments

Comments
 (0)