{"record":{"id":"e4c2fcc4f60a7786","repo":"apache/answer","slug":"database-connection-check-failed","errorCode":null,"errorMessage":"database connection check failed","messagePattern":"database connection check failed","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":264,"sourceCode":"\t\t}\n\t\tbytes[i] = fullCharset[charIndex.Int64()]\n\t}\n\n\tfor i := len(bytes) - 1; i > 0; i-- {\n\t\tj, err := rand.Int(rand.Reader, big.NewInt(int64(i+1)))\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tbytes[i], bytes[j.Int64()] = bytes[j.Int64()], bytes[i]\n\t}\n\n\treturn string(bytes), nil\n}\n\nfunc initDatabase(driver, connection string) (*xorm.Engine, error) {\n\tdataConf := &data.Database{Driver: driver, Connection: connection}\n\tif !CheckDBConnection(dataConf) {\n\t\treturn nil, fmt.Errorf(\"database connection check failed\")\n\t}\n\n\tengine, err := data.NewDB(false, dataConf)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn engine, nil\n}\n\nfunc printWarning(msg string) {\n\tif runtime.GOOS == \"windows\" {\n\t\tfmt.Printf(\"[WARNING] %s\\n\", msg)\n\t} else {\n\t\tfmt.Printf(\"\\033[31m[WARNING] %s\\033[0m\\n\", msg)\n\t}\n}\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L246-L282","documentation":"Sentinel error from initDatabase when CheckDBConnection cannot establish a working connection using the driver and connection string from config.yaml. It is a generic guard: the at-fault input is the database driver/connection configuration, and no underlying driver error is preserved — check CheckDBConnection logs for the real cause.","triggerScenarios":"Thrown at internal/cli/reset_password.go:264 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the driver and connection string passed via CLI flags (e.g., mysql/postgres driver, correct host, port, credentials)","Test connectivity manually from the same host (ping, nc to the DB port, or a DB client login)","Check that the database server is running and reachable (firewall, DNS, network policy)","Confirm credentials in the connection string are valid and the database exists","Review CheckDBConnection to see the underlying ping/timeout error it reports"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}