siyuan-note/siyuan · error

ErrInvalidID

ErrInvalidID

Error message

invalid id

What it means

ErrInvalidID is a sentinel error meaning the supplied ID string does not match SiYuan's node-ID format (ast.IsNodeIDPattern). The kernel validates IDs before doing any database or repository work to fail fast on malformed input. It is returned by attribute-view rendering and repo-snapshot resolution APIs, among others.

Solutions

  1. Validate the ID client-side against the SiYuan ID pattern before calling the API
  2. Fetch the correct ID via the list/query APIs (e.g. /api/attrv/getAttrView or SQL search) instead of hard-coding it
  3. Check whether the ID was truncated or mangled by serialization/URL handling
  4. Match with errors.Is(err, model.ErrInvalidID) and return a 'bad identifier' message to the caller

Example fix

// before
viewable, av, _, err := model.RenderAttributeViewWithTarget(avID, ...)
// after
if !ast.IsNodeIDPattern(avID) {
    return fmt.Errorf("invalid attribute view ID: %q", avID)
}
viewable, av, _, err := model.RenderAttributeViewWithTarget(avID, ...)
Defensive patterns

Strategy: validation

Validate before calling

func isValidSiYuanID(id string) bool { return ast.IsNodeIDPattern(id) }

Try / catch

if err != nil {
    if errors.Is(err, model.ErrInvalidID) {
        return fmt.Errorf("bad identifier %q: %w", avID, err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling RenderAttributeViewWithTarget or ResolveRepoSnapshotAttributeViewBoxID (and other ID-validating model functions) with an avID/blockID that is not a well-formed node ID (wrong length, illegal characters, empty string).

Common situations: Passing a database/attribute-view name instead of its ID; truncated or hand-edited IDs; plugins constructing IDs programmatically without the ID generator; stale client code after a block was recreated with a new ID.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/be6cc0978e6d2084. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/tree.go:216

	if err = treenode.CheckSpecJSON(data); nil != err {
		return
	}
	ret, err = dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
	if err != nil {
		logging.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
		return
	}
	return
}

var (
	ErrBoxNotFound   = errors.New("notebook not found")
	ErrBoxClosed     = errors.New("notebook closed")
	ErrBlockNotFound = errors.New("block not found")
	ErrTreeNotFound  = errors.New("tree not found")
	ErrIndexing      = errors.New("indexing")
	ErrBoxUnindexed  = errors.New("notebook unindexed")
	ErrInvalidID     = errors.New("invalid id")
)

func LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {
	return LoadTreeByBlockIDWithReindexInBox(id, "")
}

// LoadTreeByBlockIDWithReindexInBox 与 LoadTreeByBlockIDWithReindex 一致,但按 boxID 路由 blocktree 查询。
func LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err error) {
	if "" == id {
		logging.LogWarnf("block id is empty")
		return nil, ErrTreeNotFound
	}

	bt := treenode.GetBlockTreeInBox(id, boxID)
	if nil == bt && "" == boxID {
		// boxID 未知时(如通用打开入口),遍历所有已打开的加密笔记本查找
		for _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {
			if encBT := treenode.GetBlockTreeInBox(id, encBoxID); nil != encBT {

View on GitHub (pinned to 9f775e8a12)