{"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":485,"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":467,"sourceCodeEnd":503,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import.go#L467-L503","documentation":"When the archive contains .siyuan notebook-document metadata (boxDocMetaName), importSY0 validates it: spec version must equal boxDocMetaSpec and BoxDocID must match a node-ID pattern. Otherwise importedMetadataErr is set to this sentinel error 'invalid imported notebook document metadata', which later surfaces as the generic invalid-archive error (i18n key 199) when autoDetect is on.","triggerScenarios":"Importing a notebook-bundle .sy.zip whose .siyuan/<boxDocMetaName> file has an unknown spec version, a malformed/missing BoxDocID, or JSON that unmarshals incorrectly.","commonSituations":"Hand-edited or truncated metadata files inside a re-packed archive; archives produced by newer SiYuan versions with a higher meta spec imported into an older kernel; corrupted sync/backup artifacts.","solutions":["Re-export the notebook bundle with a matching (current) SiYuan version","Fix or remove the .siyuan metadata file in the archive (import will then treat it as a plain document archive)","Upgrade the SiYuan kernel so it supports the metadata spec used by the archive"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const meta = JSON.parse(fs.readFileSync(path.join(root, \".siyuan\", \"boxdoc.json\"), \"utf8\"));\nif (meta.spec !== 1 || !/^[0-9]{14}-[a-z0-9]{7}$/.test(meta.boxDocID)) {\n  throw new Error(\"boxdoc metadata has unsupported spec or malformed ID\");\n}","typeGuard":"const isValidBoxDocMeta = (meta) => meta && typeof meta === \"object\" && typeof meta.BoxDocID === \"string\" && /^[0-9]{14}-[a-z0-9]{7}$/.test(meta.BoxDocID);","tryCatchPattern":null,"preventionTips":["Do not hand-edit .siyuan metadata files inside archives","Import archives with a kernel version that supports their metadata spec","Re-export rather than copying metadata between archives"],"tags":["import","metadata","validation","version-mismatch"],"backgroundTag":"schema-validation-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}