siyuan-note/siyuan · error

ErrWrongLayoutType

ErrWrongLayoutType

Error message

wrong layout type

What it means

ErrWrongLayoutType is returned by layout-changing operations (changeAttrViewLayout, setAttrViewCardLayout, setAttrViewColFullRow, setAttrViewCardCoverPosition, CreateAttributeViewDatabase) when the supplied layout value is not one of the supported types (table/gallery/kanban) or when a card-layout/cover/col-full operation is applied to a view whose layout doesn't accept that value.

Source

Thrown at kernel/av/av.go:1345

			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")
	ErrRichTextSpecMismatch   = errors.New("attribute view rich text requires storage spec 9")
	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,逗号分隔
	NodeAttrContextFilter  = "custom-sy-av-context-filter" // 用于保存数据库块独有的上下文筛选配置
	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 8641553a1f)

Solutions

  1. Restrict layout values to the av.LayoutTypeTable / av.LayoutTypeGallery / av.LayoutTypeKanban constants
  2. Validate the requested layout against the current view type before calling card/cover/col-full setters
  3. Read the layout options from the API/model layer instead of inventing strings
  4. Handle the error and fall back to the view's existing layout

Example fix

// before
changeAttrViewLayout(avID, viewID, "list") // ErrWrongLayoutType
// after
layout := "list"
switch layout {
case "table", "gallery", "kanban":
    changeAttrViewLayout(avID, viewID, layout)
default:
    layout = "table" // safe fallback
    changeAttrViewLayout(avID, viewID, layout)
}
Defensive patterns

Strategy: validation

Validate before calling

switch layout {
case "table", "gallery", "kanban":
default:
    return fmt.Errorf("unsupported layout %q", layout)
}

Type guard

func isSupportedLayout(l string) bool {
    return l == "table" || l == "gallery" || l == "kanban"
}

Try / catch

err := changeAttrViewLayout(avID, viewID, layout)
if errors.Is(err, av.ErrWrongLayoutType) {
    log.Warnf("layout %q rejected, keeping current", layout)
    return nil
}

Prevention

When it happens

Trigger: Passing a layout string other than 'table' | 'gallery' | 'kanban' to changeAttrViewLayout or CreateAttributeViewDatabase; calling setAttrViewCardLayout with a card layout value invalid for the kanban view; applying table-specific ops to non-table views.

Common situations: A plugin hardcoding a layout name (e.g. 'list' or a misspelling); older plugin code using a layout value removed from the allowed set; front-end sending an unvalidated layout from user input.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/70fa901e4e1263a9. Report an issue: GitHub.