siyuan-note/siyuan · error

ErrInvalidBoxID

ErrInvalidBoxID

Error message

invalid box id

What it means

ErrInvalidBoxID indicates the supplied notebook (box) ID is non-empty but fails ast.IsNodeIDPattern. Both writeAttributeViewData and the encrypted-data hook (encrypted_hook.go) validate the boxID before reading/writing AV data, because the box ID is used as key material in the encrypted notebook envelope and as a storage path segment.

Source

Thrown at kernel/av/av.go:1341

	av := filepath.Join(util.DataDir, "storage", "av")
	ret = filepath.Join(av, avID+".json")
	if !gulu.File.IsDir(av) {
		if err := os.MkdirAll(av, 0755); err != nil {
			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. Validate with ast.IsNodeIDPattern before calling; otherwise pass an empty boxID when the notebook is unknown and let the code resolve it
  2. Obtain boxID via notebook listing (conf notebook root path -> id) instead of manual strings
  3. Trim the ID from full paths with filepath.Base and strip extensions
  4. For encrypted notebooks, double-check the ID matches the actual notebook opened in the workspace

Example fix

// before
err := av.WriteAttributeViewData(data, avID, boxID) // boxID = "/data/notebooks/foo" -> ErrInvalidBoxID
// after
boxID = filepath.Base(strings.TrimRight(boxID, "/"))
if boxID != "" && !ast.IsNodeIDPattern(boxID) {
    return fmt.Errorf("invalid box id: %q", boxID)
}
err := av.WriteAttributeViewData(data, avID, boxID)
Defensive patterns

Strategy: validation

Validate before calling

if boxID != "" && !ast.IsNodeIDPattern(boxID) {
    return fmt.Errorf("invalid box id: %q", boxID)
}

Type guard

func isValidBoxID(s string) bool { return s == "" || ast.IsNodeIDPattern(s) }

Try / catch

err := av.WriteAttributeViewData(data, avID, boxID)
if errors.Is(err, av.ErrInvalidBoxID) {
    return fmt.Errorf("boxID %q is not a notebook id; resolve it from conf notebooks first", boxID)
}

Prevention

When it happens

Trigger: Passing a malformed boxID (garbage string, path fragment, extension included) to writeAttributeViewData or to AV operations that route through the encrypted hook's validation where boxID != "" and !ast.IsNodeIDPattern(boxID).

Common situations: Hardcoding a notebook name instead of its ID; deriving boxID from a filesystem path incorrectly; using an empty-ish placeholder that is non-empty but invalid; tests feeding deliberately wrong IDs (TestRejectInvalidAttributeViewPathIDs).

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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