Skip to content

Commit a0d89ad

Browse files
Fix error handling
1 parent 9807241 commit a0d89ad

1 file changed

Lines changed: 2 additions & 13 deletions

File tree

pgutils/connector.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,21 @@ func NewConnectionStringProviderFromURLString(ctx context.Context, rawURL string
7373
// ToConnector wraps a ConnectionStringProvider as a driver.Connector.
7474
// Each Connect(ctx) call asks the provider for a fresh DSN.
7575
func ToConnector(provider ConnectionStringProvider) driver.Connector {
76-
if provider == nil {
77-
panic("pgutils: ToConnector called with nil ConnectionStringProvider")
78-
}
7976
return &postgresqlConnector{connectionStringProvider: provider}
8077
}
8178

8279
// WithSchemaSearchPath returns a ConnectionStringProvider that appends search_path
8380
// to the DSN produced by the underlying provider.
84-
//
85-
// This is a "must-style" helper intended for fluent call chaining.
86-
// It panics if provider is nil, if the underlying provider errors, or if the
87-
// search_path cannot be applied (e.g., already set).
8881
func WithSchemaSearchPath(provider ConnectionStringProvider, searchPath string) ConnectionStringProvider {
89-
if provider == nil {
90-
panic("pgutils: WithSchemaSearchPath called with nil ConnectionStringProvider")
91-
}
92-
9382
return connectionStringProviderFunc(func(ctx context.Context) (string, error) {
9483
dsn, err := provider.ConnectionString(ctx)
9584
if err != nil {
96-
panic(fmt.Errorf("pgutils: ConnectionString failed: %w", err))
85+
return "", fmt.Errorf("ConnectionString failed: %w", err)
9786
}
9887

9988
dsnWithPath, err := addSearchPathToURL(dsn, searchPath)
10089
if err != nil {
101-
panic(fmt.Errorf("pgutils: applying schema search path failed: %w", err))
90+
return "", fmt.Errorf("applying schema search path failed: %w", err)
10291
}
10392

10493
return dsnWithPath, nil

0 commit comments

Comments
 (0)