siyuan-note/siyuan · error · ErrWrongLayoutType

wrong layout type

Error message

wrong layout type

What it means

ErrWrongLayoutType is the sentinel error for unsupported or mismatched view layouts in the SiYuan attribute-view engine. Only LayoutTypeTable, LayoutTypeGallery, and LayoutTypeKanban are valid (see the switch in kernel/model/attribute_view_create.go:62-68 and changeAttrViewLayout at kernel/model/attribute_view.go:1388-1396); layout-specific operations additionally require the view to actually be of that layout (kernel/model/attribute_view.go:1977 for card-cover ops).

Solutions

  1. Normalize the layout before calling: default to av.LayoutTypeTable when the input is empty and reject anything not in {table, gallery, kanban}
  2. Verify view.LayoutType matches the operation's requirement (gallery/kanban for cover settings) before dispatching
  3. If you need another layout, check the installed SiYuan version's supported set instead of assuming; upgrade both kernel and frontend together
  4. Inspect the exact LayoutType via view.GetType() from a fresh render response

Example fix

// before
view, err := model.CreateAttributeView(name, av.LayoutType(hookedLayout), cols)

// after
var layout av.LayoutType
switch hookedLayout {
case av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:
    layout = hookedLayout
default:
    layout = av.LayoutTypeTable
}
view, err := model.CreateAttributeView(name, layout, cols)
Defensive patterns

Strategy: validation

Validate before calling

func isSupportedLayout(l av.LayoutType) bool {
    switch l {
    case av.LayoutTypeTable, av.LayoutTypeGallery, av.LayoutTypeKanban:
        return true
    }
    return false
}
// and for cover ops:
if view.LayoutType != av.LayoutTypeGallery && view.LayoutType != av.LayoutTypeKanban {
    return nil // cover settings only apply to card layouts
}

Type guard

func isWrongLayoutType(err error) bool {
    return errors.Is(err, av.ErrWrongLayoutType)
}

Try / catch

if err := changeLayout(tx, view, newLayout); errors.Is(err, av.ErrWrongLayoutType) {
    // clamp to table and inform the user the layout is unsupported in this version
}

Prevention

When it happens

Trigger: createAttributeView with a layout string outside table/gallery/kanban; a setAttrViewLayouts/changeLayout operation passing an unknown LayoutType; calling cover-related operations (setAttrViewColCardCover or similar, kernel/model/attribute_view.go:1789, 1837, 1977, 4996) on a view whose LayoutType is table instead of gallery/kanban.

Common situations: A plugin forwards a raw layout string from user input or an older API payload; code written against a fork that added layouts (e.g. a list/calendar layout) runs against mainline; a kanban-only feature is invoked on a table view because the viewID resolved to the wrong view.

Related errors


AI-assisted analysis of siyuan-note/siyuan@afa823b6b4 (2026-08-18). Data as JSON: /api/errors/6b57ac5f762aa2fc. Report an issue: GitHub.

Appendix: source

Thrown at kernel/av/av.go:1299

			logging.LogErrorf("create attribute view dir failed: %s", err)
			return
		}
	}
	return
}

func GetAttributeViewI18n(key string) string {
	return util.AttrViewLangs[util.Lang][key].(string)
}

var (
	ErrAttributeViewNotFound  = errors.New("attribute view not found")
	ErrInvalidAttributeViewID = errors.New("invalid attribute view id")
	ErrInvalidBoxID           = errors.New("invalid box id")
	ErrViewNotFound           = errors.New("view not found")
	ErrKeyNotFound            = errors.New("key not found")
	ErrItemNotFound           = errors.New("item not found")
	ErrWrongLayoutType        = errors.New("wrong layout type")
	ErrInvalidColumnAlign     = errors.New("invalid column align")
	ErrSpecTooNew             = errors.New("attribute view spec is too new")
	ErrFilterTooDeep          = errors.New("filter nesting depth exceeds the maximum allowed")
)

const (
	NodeAttrNameAvs        = "custom-avs"                 // 用于标记块所属的属性视图,逗号分隔 av id
	NodeAttrView           = "custom-sy-av-view"          // 用于标记块所属的属性视图视图 view id Database block support specified view https://github.com/siyuan-note/siyuan/issues/10443
	NodeAttrVisibleViewIDs = "custom-sy-av-visible-views" // 用于标记数据库块显示的视图 ID,逗号分隔
	NodeAttrViewStaticText = "custom-sy-av-s-text"        // 用于标记块所属的属性视图静态文本 Database-bound block primary key supports setting static anchor text https://github.com/siyuan-note/siyuan/issues/10049

	NodeAttrViewNames = "av-names" // 用于临时标记块所属的属性视图名称,空格分隔
)

View on GitHub (pinned to afa823b6b4)