siyuan-note/siyuan · error

ErrInvalidColumnAlign

ErrInvalidColumnAlign

Error message

invalid column align

What it means

ErrInvalidColumnAlign is returned when setting a table column's alignment with a value that either doesn't convert to av.TableColumnAlign or fails TableColumnAlign.IsValid(). Alignment accepts only the defined enum values (e.g. left/center/right); anything else is rejected before mutating the view.

Source

Thrown at kernel/av/av.go:1346

			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. Use the av.TableColumnAlign enum values (and IsValid()) to validate before sending the align operation
  2. Default to the existing alignment or 'left' when the requested value is invalid
  3. Clamp/whitelist alignment input on the plugin side (e.g. only 0..2 as documented)
  4. Re-read the column settings from RenderAttributeView to confirm the current valid values

Example fix

// before
setAttrViewColumnAlign(avID, viewID, colID, 9) // ErrInvalidColumnAlign
// after
align := av.TableColumnAlign(requested)
if !align.IsValid() {
    align = av.TableColumnAlignLeft
}
setAttrViewColumnAlign(avID, viewID, colID, int(align))
Defensive patterns

Strategy: validation

Validate before calling

align := av.TableColumnAlign(requestedAlign)
if !align.IsValid() {
    return fmt.Errorf("invalid column align %d", requestedAlign)
}

Type guard

func validAlign(n int) bool { return av.TableColumnAlign(n).IsValid() }

Try / catch

err := setAttrViewColumnAlign(avID, viewID, colID, requested)
if errors.Is(err, av.ErrInvalidColumnAlign) {
    err = setAttrViewColumnAlign(avID, viewID, colID, int(av.TableColumnAlignLeft))
}

Prevention

When it happens

Trigger: Calling the set-column-align operation with alignValue outside the valid TableColumnAlign set (0 -> not ok, or a number with no valid alignment mapping) in kernel/model/attribute_view.go:6792.

Common situations: A plugin or script passing raw user input as the alignment number; frontend sending undefined/NaN coerced to 0; copied integration code using an alignment constant from a different library; off-by-one on the enum indices.

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/4bb773fdbf394afd. Report an issue: GitHub.