siyuan-note/siyuan · error

invalid notebook ID

Error message

invalid notebook ID

What it means

hasEncryptedNotebookDeleteHistory checks whether any delete-op history snapshot exists for a given notebook ID before recovery proceeds. It validates the boxID with ast.IsNodeIDPattern first; if the ID is not a well-formed node ID (20-char alphanumeric pattern) the function refuses to scan and returns this sentinel error, protecting the filesystem scan from malformed input.

Solutions

  1. Verify the boxID passed to recovery is the notebook's actual node-style ID (read it from the notebook's conf.json or the notebook list API)
  2. Sanitize/reject the source of the bad ID before invoking recovery; do not pass display names or paths
  3. If the on-disk notebook dir name is not a node ID, re-create/normalize the notebook so its ID matches the expected pattern

Example fix

// before
recovered, err := hasEncryptedNotebookDeleteHistory(boxID)
// after: validate before calling
if !ast.IsNodeIDPattern(boxID) {
    return fmt.Errorf("refusing recovery: boxID %q is not a valid node ID", boxID)
}
recovered, err = hasEncryptedNotebookDeleteHistory(boxID)
Defensive patterns

Strategy: validation

Validate before calling

if boxID == "" || !ast.IsNodeIDPattern(boxID) {
    return errors.New("boxID must be a valid node-style ID before recovery")
}

Type guard

func isValidBoxID(boxID string) bool {
    return ast.IsNodeIDPattern(boxID)
}

Try / catch

ok, err := hasEncryptedNotebookDeleteHistory(boxID)
if err != nil && err.Error() == "invalid notebook ID" {
    // re-resolve the correct boxID from notebook conf and retry
    return err
}

Prevention

When it happens

Trigger: Calling recoverMasterPasswordMigration (or the test path) with a boxID that is empty, contains path characters, or otherwise fails ast.IsNodeIDPattern — e.g. a corrupted conf entry, a user-typed ID, or a notebook directory name that is not a node ID.

Common situations: A hand-edited or legacy workspace where notebook directory names predate the node-ID convention; a bug passing a display name instead of an ID; a corrupted conf.json feeding an empty boxID into recovery.

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/01c040afafe2af93. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/crypto.go:823

		for _, boxEntry := range boxEntries {
			if !boxEntry.IsDir() || !ast.IsNodeIDPattern(boxEntry.Name()) {
				continue
			}
			encrypted, checkErr := isEncryptedHistoryBoxDir(filepath.Join(snapshotDir, boxEntry.Name()))
			if checkErr != nil {
				return nil, checkErr
			}
			if encrypted {
				ret = append(ret, filepath.Join(snapshotDir, boxEntry.Name()))
			}
		}
	}
	return ret, nil
}

func hasEncryptedNotebookDeleteHistory(boxID string) (bool, error) {
	if !ast.IsNodeIDPattern(boxID) {
		return false, errors.New("invalid notebook ID")
	}
	entries, err := os.ReadDir(util.HistoryDir)
	if err != nil {
		if os.IsNotExist(err) {
			return false, nil
		}
		return false, fmt.Errorf("read history dir failed: %w", err)
	}

	deleteSuffix := "-" + HistoryOpDelete
	for _, entry := range entries {
		if !entry.IsDir() || !strings.HasSuffix(entry.Name(), deleteSuffix) {
			continue
		}
		boxDir := filepath.Join(util.HistoryDir, entry.Name(), boxID)
		if !filelock.IsExist(boxDir) {
			continue
		}

View on GitHub (pinned to 9f775e8a12)