{"record":{"id":"5bdd6d3f1367a3e2","repo":"googleapis/mcp-toolbox","slug":"sql-open-w","errorCode":null,"errorMessage":"sql.Open: %w","messagePattern":"sql\\.Open: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/clickhouse/clickhouse.go","lineNumber":208,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tencodedUser := url.QueryEscape(user)\n\tencodedPass := url.QueryEscape(pass)\n\n\tvar dsn string\n\tscheme := protocol\n\tif protocol == \"http\" && secure {\n\t\tscheme = \"https\"\n\t}\n\tdsn = fmt.Sprintf(\"%s://%s:%s@%s:%s/%s\", scheme, encodedUser, encodedPass, host, port, dbname)\n\tif scheme == \"https\" {\n\t\tdsn += \"?secure=true&skip_verify=false\"\n\t}\n\n\tpool, err := sql.Open(\"clickhouse\", dsn)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"sql.Open: %w\", err)\n\t}\n\n\tpool.SetMaxOpenConns(25)\n\tpool.SetMaxIdleConns(5)\n\tpool.SetConnMaxLifetime(5 * time.Minute)\n\n\treturn pool, nil\n}\n","sourceCodeStart":190,"sourceCodeEnd":217,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/clickhouse/clickhouse.go#L190-L217","documentation":"Wraps the error returned by database/sql's sql.Open when registering/opening the 'clickhouse' driver with the constructed DSN fails. sql.Open mostly validates driver name and DSN format; it fails here if the clickhouse driver is not registered or the DSN is malformed.","triggerScenarios":"Initialize calls initClickHouseConnectionPool, which builds the DSN from host/port/user/pass/dbname/protocol and calls sql.Open('clickhouse', dsn); failure occurs on a malformed DSN (bad characters in credentials or database name) or the clickhouse driver failing to parse the options.","commonSituations":"Passwords containing special characters (&, @, spaces) that break DSN parsing, empty required fields (host, user, dbname) producing an unparseable DSN, or protocol https with a bad query-string combination.","solutions":["Check that host, port, user, pass, and dbname fields are all non-empty and correctly quoted in the YAML","URL-encode special characters in the password or use a password without reserved characters","Inspect the underlying wrapped error for the specific DSN parse message"],"exampleFix":"// before\nuser: \"admin\"\npass: \"p@ss:word\"  # breaks DSN parsing\n// after\nuser: \"admin\"\npass: \"p%40ss%3Aword\"  # URL-encoded","handlingStrategy":"validation","validationCode":"// validate fields before initializing the source\nfunc checkCH(host, port, user, pass, dbname string) error {\n    for name, v := range map[string]string{\"host\":host,\"port\":port,\"user\":user,\"pass\":pass,\"dbname\":dbname} {\n        if v == \"\" { return fmt.Errorf(\"%s must not be empty\", name) }\n        if strings.ContainsAny(v, \" &#@\") { return fmt.Errorf(\"%s has characters that break the DSN; URL-encode them\", name) }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Go: unwrap the sql.Open error\nif _, err := initPool(...); err != nil {\n    log.Fatalf(\"clickhouse pool init failed: %v\", err) // wrapped error contains DSN parse detail\n}","preventionTips":["URL-encode special characters in passwords","Keep host/port/dbname free of whitespace and reserved characters","Test DSN parsing early with a smoke connection at startup","Pin the clickhouse-go driver version to one compatible with your DSN options"],"tags":["clickhouse","database","connection","dsn"],"backgroundTag":"database-connection-open-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}