{"record":{"id":"bc041553bf67e0f1","repo":"siyuan-note/siyuan","slug":"invalid-imported-notebook-document-metadata","errorCode":null,"errorMessage":"invalid imported notebook document metadata","messagePattern":"invalid imported notebook document metadata","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":397,"sourceCode":"\t\t}\n\t\tif removeErr := filelock.Remove(importedConfPath); removeErr != nil {\n\t\t\terr = removeErr\n\t\t\treturn\n\t\t}\n\t}\n\tvar importedBoxDocID string\n\timportedBoxDocPath := filepath.Join(unzipRootPath, \".siyuan\", boxDocMetaName)\n\thasImportedBoxDocMeta := filelock.IsExist(importedBoxDocPath)\n\tif hasImportedBoxDocMeta {\n\t\tmetaData, readErr := filelock.ReadFile(importedBoxDocPath)\n\t\tif readErr == nil {\n\t\t\tmeta := &boxDocMeta{}\n\t\t\tif unmarshalErr := gulu.JSON.UnmarshalJSON(metaData, meta); unmarshalErr != nil {\n\t\t\t\tlogging.LogWarnf(\"parse imported notebook document metadata failed: %s\", unmarshalErr)\n\t\t\t\timportedMetadataErr = unmarshalErr\n\t\t\t} else if meta.Spec != boxDocMetaSpec || !ast.IsNodeIDPattern(meta.BoxDocID) {\n\t\t\t\tlogging.LogWarnf(\"invalid imported notebook document metadata [spec=%d, id=%s]\", meta.Spec, meta.BoxDocID)\n\t\t\t\timportedMetadataErr = errors.New(\"invalid imported notebook document metadata\")\n\t\t\t} else {\n\t\t\t\timportedBoxDocID = meta.BoxDocID\n\t\t\t}\n\t\t} else {\n\t\t\tlogging.LogWarnf(\"read imported notebook document metadata failed: %s\", readErr)\n\t\t\timportedMetadataErr = readErr\n\t\t}\n\t\tif removeErr := filelock.Remove(importedBoxDocPath); removeErr != nil {\n\t\t\terr = removeErr\n\t\t\treturn\n\t\t}\n\t}\n\tnotebookExport := isSYNotebookExport(hasImportedBoxConf, hasImportedBoxDocMeta)\n\tif len(syPaths) < 1 && !notebookExport {\n\t\tlogging.LogErrorf(\"invalid .sy.zip without documents or notebook metadata [unzipRootPath=%s]\", unzipRootPath)\n\t\terr = errors.New(Conf.Language(199))\n\t\treturn\n\t}","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/import.go#L379-L415","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-export the notebook with the current SiYuan version to regenerate valid metadata","Inspect the archive's metadata file, fix or remove it, and re-zip if manual repair is acceptable","Verify the archive was not modified after export (checksums, transfer mode)","Report a bug if a stock-exported archive triggers this"],"exampleFix":"// before\nelse if meta.Spec != boxDocMetaSpec || !ast.IsNodeIDPattern(meta.BoxDocID) {\n    importedMetadataErr = errors.New(\"invalid imported notebook document metadata\")\n}\n// after (caller side): fall back to generating a new doc ID instead of failing\ndata, err := readData(id)\nif err != nil {\n    logging.LogWarnf(\"metadata invalid, will regenerate: %s\", err)\n    data = nil\n}","handlingStrategy":"validation","validationCode":"// validate metadata JSON inside the archive before import\nmetaData, _ := readArchiveFile(zipPath, root+\"/.siyuan/\"+metaName)\nvar meta map[string]interface{}\nif json.Unmarshal(metaData, &meta) != nil {\n    return errors.New(\"archive metadata JSON is corrupt\")\n}\nif id, _ := meta[\"boxDocId\"].(string); !isNodeIDPattern(id) {\n    return errors.New(\"archive metadata has invalid doc ID\")\n}","typeGuard":null,"tryCatchPattern":"// Go caller\nif err := model.ImportSYAuto(zipPath, \"\", toPath); err != nil {\n    logging.LogErrorf(\"import failed, metadata may be corrupt: %s\", err)\n    return err\n}","preventionTips":["Never hand-edit files inside exported .sy.zip archives","Verify downloads (size/checksum) before importing","Generate archives with the current SiYuan version so metadata spec matches"],"tags":["import","metadata","validation","json","notebook"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}