siyuan-note/siyuan · error

unsupported box document metadata spec

Error message

unsupported box document metadata spec [%d]

What it means

boxDoc.json carries a spec version; this error fires when the parsed spec does not equal the supported boxDocMetaSpec (currently 1). The metadata file was written by a newer (or older) incompatible format, and the kernel refuses to interpret an unknown spec rather than guessing. This is a forward/backward compatibility guard for the notebook document-node feature.

Solutions

  1. Upgrade SiYuan to the version that wrote the boxDoc.json (matching its spec)
  2. Recreate the file with spec 1: delete .siyuan/boxDoc.json so ensureBoxDoc0 rewrites it in the current format
  3. Check for mixed-version clients syncing the same workspace and align all clients to the same SiYuan version

Example fix

// before
{"spec": 2, "boxDocID": "..."}
// after
{"spec": 1, "boxDocID": "20240101120000-abcdefg"}
Defensive patterns

Strategy: try-catch

Validate before calling

var probe struct{ Spec int `json:"spec"` }
if json.Unmarshal(data, &probe) == nil && probe.Spec != 1 {
    // unsupported spec: upgrade SiYuan or delete boxDoc.json to regenerate
}

Try / catch

if _, err := readBoxDocID(boxID); err != nil && strings.Contains(err.Error(), "unsupported box document metadata spec") {
    // migrate: upgrade app version or regenerate the metadata file
}

Prevention

When it happens

Trigger: readBoxDocID (via ensureBoxDoc0 or TestBoxDocMetadataMatchesBoxID) reads a .siyuan/boxDoc.json whose spec field is 0, 2, or any value != 1 — typically a file written by a future SiYuan version.

Common situations: Opening a workspace last used by a newer SiYuan build that bumped the spec; hand-crafted boxDoc.json with a missing (spec=0) or wrong spec value; mixed-version sync between devices.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/891ecc532615952b. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/box_doc.go:74

	}
	return "/" + boxID + ".sy"
}

func readBoxDocID(boxID string) (ret string, err error) {
	data, err := filelock.ReadFile(boxDocMetaPath(boxID))
	if err != nil {
		if errors.Is(err, os.ErrNotExist) {
			err = nil
		}
		return
	}

	meta := &boxDocMeta{}
	if err = gulu.JSON.UnmarshalJSON(data, meta); err != nil {
		return "", fmt.Errorf("unmarshal box document metadata failed: %w", err)
	}
	if boxDocMetaSpec != meta.Spec {
		return "", fmt.Errorf("unsupported box document metadata spec [%d]", meta.Spec)
	}
	if !ast.IsNodeIDPattern(meta.BoxDocID) {
		return "", fmt.Errorf("invalid box document ID [%s]", meta.BoxDocID)
	}
	if boxID != meta.BoxDocID {
		return "", fmt.Errorf("box document ID [%s] does not match box ID [%s]", meta.BoxDocID, boxID)
	}
	return boxID, nil
}

func writeBoxDocID(boxID string) error {
	meta := &boxDocMeta{Spec: boxDocMetaSpec, BoxDocID: boxID}
	data, err := gulu.JSON.MarshalIndentJSON(meta, "", "  ")
	if err != nil {
		return fmt.Errorf("marshal box document metadata failed: %w", err)
	}
	return filelock.WriteFile(boxDocMetaPath(boxID), data)
}

View on GitHub (pinned to 9f775e8a12)