diff options
| author | Eugene Triguba <eugenetriguba@gmail.com> | 2024-02-25 16:08:04 -0500 |
|---|---|---|
| committer | Eugene Triguba <eugenetriguba@gmail.com> | 2024-02-25 16:08:04 -0500 |
| commit | 46f7f49ebeb7f4e8fa1f395805a0b14baee5e5bc (patch) | |
| tree | fcdf053eefc5f0c1146da57aac9285e50ff027f3 /internal/storage/db.go | |
| parent | Add better error handling for db connect (diff) | |
| download | cli-46f7f49ebeb7f4e8fa1f395805a0b14baee5e5bc.zip | |
Tweak error and doc for storage module
Diffstat (limited to 'internal/storage/db.go')
| -rw-r--r-- | internal/storage/db.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go index 26d3b3b..02683b4 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -10,18 +10,22 @@ import ( ) var ( - ErrInvalidConnectionString = errors.New("invalid database connection parameters provided") - ErrUnableToConnect = errors.New("unable to open connection to database") + ErrMalformedConnectionString = errors.New("malformed database connection parameters provided") + ErrUnableToConnect = errors.New("unable to open connection to database") ) // DBConnect establishes a connection to the database using the driver -// and connection information. +// and connection information. Only "postgres" is supported as the driver. // -// Note that only "postgres" is supported as the driver right now. +// The following errors may be returned: +// - ErrMalformedConnectionString: The provided connection parameters are +// not in a valid format. +// - ErrUnableToConnect: Unable to make a connection to the database with +// the provided connection parameters. func DBConnect(driver string, connectionParams string) (*sql.DB, error) { db, err := sql.Open(driver, connectionParams) if err != nil { - return nil, fmt.Errorf("%w: %v", ErrInvalidConnectionString, err) + return nil, fmt.Errorf("%w: %v", ErrMalformedConnectionString, err) } // Note: `sql.Open` only validates the connection string we provided is sane. |