mattermost-community/focalboard · error

block ids and patches need to match

Error message

block ids and patches need to match

What it means

ErrBlockIDsAndPatchesMissmatchInBoardsAndBlocks is returned by BoardsAndBlocks.IsValid() when the patch variant's BlockIDs and BlockPatches arrays do not correspond one-to-one. Every block patch must have exactly one matching block ID.

Source

Thrown at server/model/boards_and_blocks.go:18

package model

import (
	"encoding/json"
	"errors"
	"fmt"
	"io"

	"github.com/mattermost/focalboard/server/utils"

	"github.com/mattermost/mattermost/server/public/shared/mlog"
)

var ErrNoBoardsInBoardsAndBlocks = errors.New("at least one board is required")
var ErrNoBlocksInBoardsAndBlocks = errors.New("at least one block is required")
var ErrNoTeamInBoardsAndBlocks = errors.New("team ID cannot be empty")
var ErrBoardIDsAndPatchesMissmatchInBoardsAndBlocks = errors.New("board ids and patches need to match")
var ErrBlockIDsAndPatchesMissmatchInBoardsAndBlocks = errors.New("block ids and patches need to match")

type BlockDoesntBelongToAnyBoardErr struct {
	blockID string
}

func (e BlockDoesntBelongToAnyBoardErr) Error() string {
	return fmt.Sprintf("block %s doesn't belong to any board", e.blockID)
}

// BoardsAndBlocks is used to operate over boards and blocks at the
// same time
// swagger:model
type BoardsAndBlocks struct {
	// The boards
	// required: false
	Boards []*Board `json:"boards"`

	// The blocks

View on GitHub (pinned to a84bbb65e3)

Solutions

  1. Ensure BlockIDs.length === BlockPatches.length before sending
  2. Derive both arrays from the same filtered collection in a single pass
  3. Re-fetch blocks and rebuild the patch payload if the board changed during the operation

Example fix

// before
payload.blockIDs = blocks.map(b => b.id)
payload.blockPatches = patches // possibly different length
// after
if (patches.length !== payload.blockIDs.length) {
  throw new Error('block ids and patches must align')
}
payload.blockPatches = patches
Defensive patterns

Strategy: validation

Validate before calling

if (payload.blockIDs.length !== payload.blockPatches.length) {
  throw new Error('block ids and patches must be the same length')
}

Try / catch

try {
  await client.patchBoardsAndBlocks(payload)
} catch (err) {
  if (err.message?.includes('block ids and patches need to match')) {
    console.error('Align blockIDs and blockPatches arrays 1:1')
  } else throw err
}

Prevention

When it happens

Trigger: PATCH /api/v2/boards-and-blocks with BlockIDs and BlockPatches arrays of differing lengths or misaligned order.

Common situations: Bulk block update scripts with divergent filtering between IDs and patches; concurrent modifications where a block vanished between ID collection and patch construction.

Related errors


AI-assisted analysis of mattermost-community/focalboard@a84bbb65e3 (2026-08-30). Data as JSON: /api/errors/28619de79df0613f. Report an issue: GitHub.