{"record":{"id":"eda890fd8388ac99","repo":"apache/answer","slug":"connect-database-failed-w","errorCode":null,"errorMessage":"connect database failed: %w","messagePattern":"connect database failed: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cli/reset_password.go","lineNumber":79,"sourceCode":"\tcharsetSpecial,\n}\n\ntype ResetPasswordOptions struct {\n\tEmail    string\n\tPassword string\n}\n\nfunc ResetPassword(ctx context.Context, dataDirPath string, opts *ResetPasswordOptions) error {\n\tpath.FormatAllPath(dataDirPath)\n\n\tconfig, err := conf.ReadConfig(path.GetConfigFilePath())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read config file failed: %w\", err)\n\t}\n\n\tdb, err := initDatabase(config.Data.Database.Driver, config.Data.Database.Connection)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"connect database failed: %w\", err)\n\t}\n\tdefer func() {\n\t\t_ = db.Close()\n\t}()\n\n\tcache, cacheCleanup, err := data.NewCache(config.Data.Cache)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initialize cache failed: %w\", err)\n\t}\n\tdefer cacheCleanup()\n\n\tdataData, dataCleanup, err := data.NewData(db, cache)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"initialize data layer failed: %w\", err)\n\t}\n\tdefer dataCleanup()\n\n\tuserRepo := user.NewUserRepo(dataData)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/internal/cli/reset_password.go#L61-L97","documentation":"ResetPassword wraps a failure from initDatabase(config.Data.Database.Driver, config.Data.Database.Connection), i.e. the CLI could not open a connection to the configured database (driver not supported or connection failed).","triggerScenarios":"Database driver string invalid (not mysql/postgres/sqlite3) or the connection DSN is unreachable — wrong host/port, DB down, bad credentials.","commonSituations":"Config points at a DB container that isn't running, credentials rotated, DNS/hostname typo, unsupported driver value in config.","solutions":["Verify database.driver and database.connection values in the config file.","Confirm the database is running and reachable (ping/port test).","Check username/password and that the driver name is one the app supports."],"exampleFix":"// before\nconnection = \"postgres://app:secret@db-host:5432/appdb\"\n// after (verify reachability, correct host/port)\nconnection = \"postgres://app:secret@127.0.0.1:5432/appdb\"","handlingStrategy":"validation","validationCode":"addr, err := net.LookupHost(\"db-host\")\nif err != nil { return fmt.Errorf(\"db host unresolvable\") }\nconn, err := net.DialTimeout(\"tcp\", \"db-host:5432\", 3*time.Second)\nif err != nil { return fmt.Errorf(\"db port closed: %w\", err) }\nconn.Close()","typeGuard":null,"tryCatchPattern":"if err := cli.ResetPassword(ctx, dataDir, opts); err != nil {\n    if strings.Contains(err.Error(), \"connect database failed\") {\n        log.Fatalf(\"verify DB driver/connection in config: %v\", err)\n    }\n}","preventionTips":["Test DB connectivity before CLI runs","Keep driver names limited to supported values","Use secrets management to avoid stale credentials"],"tags":["database","connection","config"],"backgroundTag":"connection-refused","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}