Skip to content
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

[Bug] Handling connection errors when initializing database connection #88

Open
ksamirdev opened this issue Nov 16, 2023 · 0 comments
Open

Comments

@ksamirdev
Copy link

The code doesn't report an error when the libsql server is unavailable. When I attempt to perform database queries, I encounter the following error message:

2023/11/16 20:22:23 <nil> failed to execute SQL: SELECT * FROM user
Post "http://127.0.0.1:8080/v2/pipeline": dial tcp 127.0.0.1:8080: connect: connection refused

I would expect the code to return an error message indicating that the libsql server is unavailable instead of silently failing.

func InitializeDB() (*sql.DB, error) {
    db, err := sql.Open("libsql", DB_URL)
    if err != nil {
        return nil, fmt.Errorf("failed to open db %s: %w", DB_URL, err)
    }

    err = db.Ping()
    if err != nil {
        return nil, fmt.Errorf("failed to ping database: %w", err)
    }

    return db, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant