{"record":{"id":"3812b1b345f1a384","repo":"gastownhall/beads","slug":"uow-open-db-w","errorCode":null,"errorMessage":"uow: open db: %w","messagePattern":"uow: open db: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/uow/dolt_sql_provider.go","lineNumber":384,"sourceCode":"\treturn b.heal, nil\n}\n\nfunc buildDSN(ep proxy.Endpoint, database, user, password, tlsConfigName string) string {\n\treturn util.DoltServerDSN{\n\t\tHost:            ep.Host,\n\t\tPort:            ep.Port,\n\t\tUser:            user,\n\t\tPassword:        password,\n\t\tDatabase:        database,\n\t\tTLSConfigName:   tlsConfigName,\n\t\tClientFoundRows: true,\n\t}.String()\n}\n\nfunc openDB(ctx context.Context, dsn string) (*sql.DB, error) {\n\tconn, err := sql.Open(\"mysql\", dsn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"uow: open db: %w\", err)\n\t}\n\tif err := conn.PingContext(ctx); err != nil {\n\t\treturn nil, errors.Join(fmt.Errorf(\"uow: ping db: %w\", err), conn.Close())\n\t}\n\treturn conn, nil\n}\n\nfunc openAndInitSchema(ctx context.Context, ep proxy.Endpoint, database, rootUser, rootPassword, tlsConfigName string, teamServer bool, expectedProjectID string, opts providerOptions) (UnitOfWorkProvider, error) {\n\tinitDB, err := openDB(ctx, buildDSN(ep, \"\", rootUser, rootPassword, tlsConfigName))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tinitProvider := &doltSQLProvider{\n\t\tdefaultBranch:     defaultBranch,\n\t\tdb:                initDB,\n\t\tserverEndpoint:    \"tcp:\" + ep.Address(),\n\t\tteamServer:        teamServer,","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/uow/dolt_sql_provider.go#L366-L402","documentation":"openDB opens a database/sql connection to the Dolt SQL server using the mysql driver. This error wraps a failure returned by sql.Open itself. It is thrown when the DSN is malformed or the mysql driver cannot be initialized — before any network contact is made (sql.Open does not connect; failures here are configuration/driver-level, not connectivity).","triggerScenarios":"sql.Open(\"mysql\", dsn) returns a non-nil error — typically an unparsable DSN produced by buildDSN (bad characters in host, user, password, database, or TLS config name) or unregistered \"mysql\" driver.","commonSituations":"Endpoint config containing characters that break DSN escaping (special chars in password without escaping); wrong endpoint format in bd config; binary built without the mysql driver import (rare).","solutions":["Check the endpoint/user/password/TLS settings feeding buildDSN; escape special characters (e.g. '@', ':', '/', '(' in passwords) or use the go-sql-driver URL form.","Verify the Dolt server endpoint uses host:port format (e.g. tcp:localhost:3306).","Rebuild with the go-sql-driver/mysql driver registered (blank import present) if using a custom build.","Print/log the constructed DSN (redacting password) to spot malformed fields."],"exampleFix":"// before: unescaped password breaks DSN\npassword = \"p@ss:word\"\n// after: escape or URL-encode special characters in credentials\npassword = \"p%40ss%3Aword\"","handlingStrategy":"validation","validationCode":"// Pre-validate endpoint and credentials before calling the library\nfunc validateEndpoint(ep string) error {\n    host, port, err := net.SplitHostPort(strings.TrimPrefix(ep, \"tcp:\"))\n    if err != nil || host == \"\" || port == \"\" {\n        return fmt.Errorf(\"invalid endpoint %q, want host:port\", ep)\n    }\n    return nil\n}\n// Reject DSN-breaking characters in credentials\nif strings.ContainsAny(password, \"@:/()\") {\n    return fmt.Errorf(\"password contains characters requiring DSN escaping\")\n}","typeGuard":"func isOpenDBError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"uow: open db:\")\n}","tryCatchPattern":"p, err := uow.Open(ctx, cfg)\nif err != nil {\n    if strings.Contains(err.Error(), \"uow: open db:\") {\n        return fmt.Errorf(\"bad DSN/config (check endpoint, escaping of user/password/TLS name): %w\", err)\n    }\n    return err\n}","preventionTips":["Use simple host:port endpoints without stray characters","Escape or URL-encode special characters in passwords and usernames","Validate configuration with a dry-run/inspect command before init","Keep the go-sql-driver/mysql import in custom builds"],"tags":["database","connection","dsn","dolt"],"backgroundTag":"invalid-dsn","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}