siyuan-note/siyuan · error

invalid imported notebook document metadata

Error message

invalid imported notebook document metadata

What it means

When reading a notebook export's document metadata file (.siyuan metadata recording the original box/doc ID), importSY0 validates the spec version and that the ID is a valid node ID. If parsing fails or the spec/ID check fails, it records 'invalid imported notebook document metadata'. Unlike the user-facing Language(199) errors, this raw error surfaces when metadata exists but its contents are malformed.

Source

Thrown at kernel/model/import.go:397

		}
		if removeErr := filelock.Remove(importedConfPath); removeErr != nil {
			err = removeErr
			return
		}
	}
	var importedBoxDocID string
	importedBoxDocPath := filepath.Join(unzipRootPath, ".siyuan", boxDocMetaName)
	hasImportedBoxDocMeta := filelock.IsExist(importedBoxDocPath)
	if hasImportedBoxDocMeta {
		metaData, readErr := filelock.ReadFile(importedBoxDocPath)
		if readErr == nil {
			meta := &boxDocMeta{}
			if unmarshalErr := gulu.JSON.UnmarshalJSON(metaData, meta); unmarshalErr != nil {
				logging.LogWarnf("parse imported notebook document metadata failed: %s", unmarshalErr)
				importedMetadataErr = unmarshalErr
			} else if meta.Spec != boxDocMetaSpec || !ast.IsNodeIDPattern(meta.BoxDocID) {
				logging.LogWarnf("invalid imported notebook document metadata [spec=%d, id=%s]", meta.Spec, meta.BoxDocID)
				importedMetadataErr = errors.New("invalid imported notebook document metadata")
			} else {
				importedBoxDocID = meta.BoxDocID
			}
		} else {
			logging.LogWarnf("read imported notebook document metadata failed: %s", readErr)
			importedMetadataErr = readErr
		}
		if removeErr := filelock.Remove(importedBoxDocPath); removeErr != nil {
			err = removeErr
			return
		}
	}
	notebookExport := isSYNotebookExport(hasImportedBoxConf, hasImportedBoxDocMeta)
	if len(syPaths) < 1 && !notebookExport {
		logging.LogErrorf("invalid .sy.zip without documents or notebook metadata [unzipRootPath=%s]", unzipRootPath)
		err = errors.New(Conf.Language(199))
		return
	}

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Re-export the notebook with the current SiYuan version to regenerate valid metadata
  2. Inspect the archive's metadata file, fix or remove it, and re-zip if manual repair is acceptable
  3. Verify the archive was not modified after export (checksums, transfer mode)
  4. Report a bug if a stock-exported archive triggers this

Example fix

// before
else if meta.Spec != boxDocMetaSpec || !ast.IsNodeIDPattern(meta.BoxDocID) {
    importedMetadataErr = errors.New("invalid imported notebook document metadata")
}
// after (caller side): fall back to generating a new doc ID instead of failing
data, err := readData(id)
if err != nil {
    logging.LogWarnf("metadata invalid, will regenerate: %s", err)
    data = nil
}
Defensive patterns

Strategy: validation

Validate before calling

// validate metadata JSON inside the archive before import
metaData, _ := readArchiveFile(zipPath, root+"/.siyuan/"+metaName)
var meta map[string]interface{}
if json.Unmarshal(metaData, &meta) != nil {
    return errors.New("archive metadata JSON is corrupt")
}
if id, _ := meta["boxDocId"].(string); !isNodeIDPattern(id) {
    return errors.New("archive metadata has invalid doc ID")
}

Try / catch

// Go caller
if err := model.ImportSYAuto(zipPath, "", toPath); err != nil {
    logging.LogErrorf("import failed, metadata may be corrupt: %s", err)
    return err
}

Prevention

When it happens

Trigger: Importing a notebook .sy.zip whose document metadata JSON fails to unmarshal, whose meta.Spec != boxDocMetaSpec (wrong format version), or whose BoxDocID does not match ast.IsNodeIDPattern.

Common situations: Archives edited by hand or by scripts breaking the metadata JSON; exports from newer/older versions with a different metadata spec; corruption during transfer; third-party tools generating .sy.zip files with fabricated metadata.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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