{"record":{"id":"c9df324eb69c900c","repo":"mattermost-community/focalboard","slug":"insertboard-error-occurred-while-fetching-existing","errorCode":null,"errorMessage":"insertBoard error occurred while fetching existing board %s: %w","messagePattern":"insertBoard error occurred while fetching existing board (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/services/store/sqlstore/board.go","lineNumber":329,"sourceCode":"\t\t\tmlog.Err(err),\n\t\t)\n\t\treturn nil, err\n\t}\n\n\tcardPropertiesBytes, err := s.MarshalJSONB(board.CardProperties)\n\tif err != nil {\n\t\ts.logger.Error(\n\t\t\t\"failed to marshal board.CardProperties\",\n\t\t\tmlog.String(\"board_id\", board.ID),\n\t\t\tmlog.String(\"board.CardProperties\", fmt.Sprintf(\"%v\", board.CardProperties)),\n\t\t\tmlog.Err(err),\n\t\t)\n\t\treturn nil, err\n\t}\n\n\texistingBoard, err := s.getBoard(db, board.ID)\n\tif err != nil && !model.IsErrNotFound(err) {\n\t\treturn nil, fmt.Errorf(\"insertBoard error occurred while fetching existing board %s: %w\", board.ID, err)\n\t}\n\n\tinsertQuery := s.getQueryBuilder(db).Insert(\"\").\n\t\tColumns(boardFields(\"\")...)\n\n\tnow := utils.GetMillis()\n\tboard.ModifiedBy = userID\n\tboard.UpdateAt = now\n\n\tinsertQueryValues := map[string]interface{}{\n\t\t\"id\":               board.ID,\n\t\t\"team_id\":          board.TeamID,\n\t\t\"channel_id\":       board.ChannelID,\n\t\t\"created_by\":       board.CreatedBy,\n\t\t\"modified_by\":      board.ModifiedBy,\n\t\t\"type\":             board.Type,\n\t\t\"title\":            board.Title,\n\t\t\"minimum_role\":     board.MinimumRole,","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/mattermost-community/focalboard/blob/a84bbb65e32edf972856b329417096ac413518e9/server/services/store/sqlstore/board.go#L311-L347","documentation":"insertBoard first checks whether a board with the same ID already exists (to decide upsert vs insert) by calling getBoard; if that lookup fails with an error OTHER than not-found, this wrapped error is returned. It signals a genuine storage problem while reading existing board state, not a duplicate-ID situation.","triggerScenarios":"InsertBoard (or patchBoard/insertBoardWithAdmin/createBoardsAndBlocks paths) when getBoard returns a connection error, table-missing error, permission failure, or any non-ErrNotFound database error.","commonSituations":"DB connection drops mid-request; migrations incomplete so the boards table doesn't exist; misconfigured DSN pointing at a wrong/locked database; transient read replicas issues.","solutions":["Inspect the wrapped err (%w) for the underlying DB error (connection refused, unknown table, etc.)","Verify database connectivity and that the boards table exists (run migrations)","Retry the operation if the failure was transient (connection blip)","Check the DSN/credentials in your configuration match a healthy database"],"exampleFix":"// no code fix in caller; verify infra\n// before\n// server fails: insertBoard error occurred while fetching existing board ...\n// after: ensure DB reachable and migrated\nmigrate_db.sh && restart server","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"board, err := store.InsertBoard(board, userID)\nif err != nil && strings.Contains(err.Error(), \"error occurred while fetching existing board\") {\n    // transient DB read failure — retry after checking connectivity\n    time.Sleep(250 * time.Millisecond)\n    board, err = store.InsertBoard(board, userID)\n}","preventionTips":["Monitor DB connectivity; alert on connection errors before they surface as insert failures","Run all migrations on deploy so boards table always exists","Verify DSN/credentials point at the correct, writable database","Use a connection pool with health checks (ping) to drop stale connections"],"tags":["database","upsert","storage"],"backgroundTag":"board-lookup-failed","analyzedSha":"a84bbb65e32edf972856b329417096ac413518e9","analyzedAt":"2026-08-30T09:22:20.720Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}