{"record":{"id":"60fa1383eba088a4","repo":"siyuan-note/siyuan","slug":"prepare-export-asset-s-w","errorCode":null,"errorMessage":"prepare export asset [%s]: %w","messagePattern":"prepare export asset \\[(.+?)\\]: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/asset_download_read.go","lineNumber":272,"sourceCode":"\t\t}\n\t\tfor _, dest := range dests {\n\t\t\tdest = string(html.DecodeDestination([]byte(dest)))\n\t\t\tif fragment := strings.IndexByte(dest, '#'); fragment >= 0 {\n\t\t\t\tdest = dest[:fragment]\n\t\t\t}\n\t\t\tif !strings.HasPrefix(AssetPathWithoutQuery(dest), \"assets/\") {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tabsPath, resolveErr := GetAssetAbsPathInBox(dest, tree.Box)\n\t\t\tif resolveErr != nil {\n\t\t\t\treturn resolveErr\n\t\t\t}\n\t\t\tassets[absPath] = true\n\t\t}\n\t}\n\tfor absPath := range assets {\n\t\tif err = EnsureAssetPrefixLocal(absPath); err != nil {\n\t\t\treturn fmt.Errorf(\"prepare export asset [%s]: %w\", filepath.Base(absPath), err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc prepareExportBlockAssets(id string, includeSubDocs bool) error {\n\tbt := getExportBlockTree(id)\n\tif bt == nil {\n\t\treturn nil\n\t}\n\tdocPaths := []string{bt.Path}\n\tif includeSubDocs {\n\t\tif box := Conf.Box(bt.BoxID); box != nil {\n\t\t\tlistPath := strings.TrimSuffix(bt.Path, \".sy\")\n\t\t\tif IsBoxDoc(bt.BoxID, bt.RootID) {\n\t\t\t\tlistPath = \"/\"\n\t\t\t}\n\t\t\tfor _, file := range box.ListFiles(listPath) {","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/asset_download_read.go#L254-L290","documentation":"After collecting all assets referenced by the export trees, prepareExportAssets calls EnsureAssetPrefixLocal for each; on failure it wraps the cause with 'prepare export asset [%s]: %w', naming the asset's base file name. The wrapped error is normally a download/chunk or access failure (e.g. cloud snapshot fetch, unresolved symlink, lock error from the ensure/download pipeline), so this message is an aggregation point rather than a root cause.","triggerScenarios":"exportSYZip / exportPandocConvertZip0 / prepareExportBlockAssets / TestAssetDownloadCrossNotebookExport where at least one referenced asset cannot be made locally complete: EnsureAssetPrefixLocal fails due to network/cloud errors, missing repo key, locked encrypted box, or broken symlink discovered during resolution.","commonSituations":"Exporting a document while offline when some assets live only in cloud snapshots; asset file removed from disk but still referenced; symlinked asset folders; expired cloud session mid-export.","solutions":["Read the wrapped %w cause for the root failure and fix it (network, cloud auth, repo key, unlock notebook)","Verify the named asset exists on disk under the notebook's assets directory; restore it from backup or re-upload it","Run a sync so deferred/cloud-only assets are downloaded, then retry the export","Check the underlying chunk-ensure errors (code 376 family) if the cause mentions chunk or cloud failures"],"exampleFix":"// before: opaque failure handling\nerr := model.PrepareExportBlockAssets(id, true)\nlog.Fatal(err) // \"prepare export asset [img.png]: ...\" without context\n// after: pre-flight the assets\nfor _, p := range model.CollectExportAssetPaths(id) {\n    if err := model.EnsureAssetPrefixLocal(p); err != nil {\n        log.Printf(\"asset %s unavailable: %v; sync or restore it\", p, err)\n    }\n}\nerr := model.PrepareExportBlockAssets(id, true)","handlingStrategy":"try-catch","validationCode":"for _, p := range collectExportAssetPaths(id) {\n    if _, err := os.Stat(p); err != nil { return fmt.Errorf(\"asset missing on disk: %s\", p) }\n    if err := model.EnsureAssetPrefixLocal(p); err != nil { return err }\n}","typeGuard":null,"tryCatchPattern":"err := model.PrepareExportBlockAssets(id, includeSubDocs)\nif err != nil {\n    var base string\n    if _, werr := fmt.Sscanf(err.Error(), \"prepare export asset [%s]\", &base); werr == nil {\n        log.Printf(\"export blocked by asset %s; inspect wrapped cause\", base)\n    }\n    return err // always surface the wrapped %w cause for diagnosis\n}","preventionTips":["Pre-flight EnsureAssetPrefixLocal on referenced assets before long exports","Ensure network/cloud auth is healthy so deferred assets can download","Restore or re-upload assets that were deleted from disk but remain referenced","Inspect the wrapped cause (%w) — this message names the asset, the cause names the problem"],"tags":["export","assets","error-wrapping","cloud-sync"],"backgroundTag":"api-error-response","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"}