siyuan-note/siyuan · error
prepare export asset
Error message
prepare export asset [%s]: %w
What it means
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.
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
Example fix
// before: opaque failure handling
err := model.PrepareExportBlockAssets(id, true)
log.Fatal(err) // "prepare export asset [img.png]: ..." without context
// after: pre-flight the assets
for _, p := range model.CollectExportAssetPaths(id) {
if err := model.EnsureAssetPrefixLocal(p); err != nil {
log.Printf("asset %s unavailable: %v; sync or restore it", p, err)
}
}
err := model.PrepareExportBlockAssets(id, true) Defensive patterns
Strategy: try-catch
Validate before calling
for _, p := range collectExportAssetPaths(id) {
if _, err := os.Stat(p); err != nil { return fmt.Errorf("asset missing on disk: %s", p) }
if err := model.EnsureAssetPrefixLocal(p); err != nil { return err }
} Try / catch
err := model.PrepareExportBlockAssets(id, includeSubDocs)
if err != nil {
var base string
if _, werr := fmt.Sscanf(err.Error(), "prepare export asset [%s]", &base); werr == nil {
log.Printf("export blocked by asset %s; inspect wrapped cause", base)
}
return err // always surface the wrapped %w cause for diagnosis
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/60fa1383eba088a4.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/asset_download_read.go:272
}
for _, dest := range dests {
dest = string(html.DecodeDestination([]byte(dest)))
if fragment := strings.IndexByte(dest, '#'); fragment >= 0 {
dest = dest[:fragment]
}
if !strings.HasPrefix(AssetPathWithoutQuery(dest), "assets/") {
continue
}
absPath, resolveErr := GetAssetAbsPathInBox(dest, tree.Box)
if resolveErr != nil {
return resolveErr
}
assets[absPath] = true
}
}
for absPath := range assets {
if err = EnsureAssetPrefixLocal(absPath); err != nil {
return fmt.Errorf("prepare export asset [%s]: %w", filepath.Base(absPath), err)
}
}
return nil
}
func prepareExportBlockAssets(id string, includeSubDocs bool) error {
bt := getExportBlockTree(id)
if bt == nil {
return nil
}
docPaths := []string{bt.Path}
if includeSubDocs {
if box := Conf.Box(bt.BoxID); box != nil {
listPath := strings.TrimSuffix(bt.Path, ".sy")
if IsBoxDoc(bt.BoxID, bt.RootID) {
listPath = "/"
}
for _, file := range box.ListFiles(listPath) {View on GitHub (pinned to 9f775e8a12)