{"record":{"id":"92a1c6e708a20022","repo":"siyuan-note/siyuan","slug":"all-asset-mappings-failed","errorCode":null,"errorMessage":"all asset mappings failed","messagePattern":"all asset mappings failed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/asset_relink_batch.go","lineNumber":412,"sourceCode":"\t\tif result.OK {\n\t\t\tok++\n\t\t}\n\t\tif p.batch {\n\t\t\tp.result.Items = append(p.result.Items, result)\n\t\t}\n\t}\n\tif fatal != nil {\n\t\treturn p.result, fatal\n\t}\n\tif !p.batch && len(p.items) == 1 {\n\t\titem := p.items[0]\n\t\tif item.reason != \"\" && (item.inputError || (!p.result.DryRun && !p.lookup)) {\n\t\t\treturn p.result, errors.New(item.reason)\n\t\t}\n\t\treturn p.result, nil\n\t}\n\tif ok == 0 {\n\t\treturn p.result, errors.New(\"all asset mappings failed\")\n\t}\n\treturn p.result, nil\n}\n\nfunc (p *assetRelinkPlan) apply() (err error) {\n\tp.finishPreflight()\n\tif err = p.validateSnapshot(); err != nil {\n\t\treturn err\n\t}\n\tvar files []*assetRelinkFile\n\tfor _, file := range p.files {\n\t\tif len(activeRelinkItems(file.items)) > 0 {\n\t\t\tfiles = append(files, file)\n\t\t}\n\t}\n\tvar ocrSelected []int\n\tif p.ocrPlan != nil {\n\t\tfor i, result := range p.ocrPlan.Results {","sourceCodeStart":394,"sourceCodeEnd":430,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/asset_relink_batch.go#L394-L430","documentation":"After running a batch plan, if zero mappings succeeded (ok == 0) and the plan was not a per-input early return, the whole operation is reported as failed with this error while the per-item reasons are carried in the result payload. It signals that none of the requested old paths could be resolved or relinked.","triggerScenarios":"Calling RelinkAssets/FindAssetReferencesBatch where every OldPath fails validation or resolution (files missing, escapes, encrypted boxes, bad formats), so no route produced results.","commonSituations":"Paths referencing assets deleted before the call; all paths spelled with wrong prefix (missing 'assets/', absolute paths); batch of paths from a different workspace; typos in every entry copied from an outdated list.","solutions":["Inspect the per-item reasons in the returned AssetReferencesData and fix the underlying oldPath values","Verify each oldPath exists under the data directory and uses the expected relative form before calling","Run a dry-run first to identify which mappings fail, then resubmit corrected mappings","Check you are pointing at the intended workspace (DataDir) containing those assets"],"exampleFix":"// before\nresult, err := model.RelinkAssets(ctx, mappings, false)\nif err != nil { log.Fatal(err) } // loses per-item detail\n// after\nresult, err := model.RelinkAssets(ctx, mappings, true) // dry run first\nfor _, r := range result.References { log.Printf(\"%s: %s\", r.Path, r.Reason) }\n// fix oldPath values based on reasons, then run with dryRun=false","handlingStrategy":"try-catch","validationCode":"for _, m := range mappings {\n\tif _, err := os.Stat(filepath.Join(util.DataDir, m.OldPath)); err != nil {\n\t\treturn fmt.Errorf(\"oldPath missing: %s\", m.OldPath)\n\t}\n}","typeGuard":null,"tryCatchPattern":"result, err := model.RelinkAssets(ctx, mappings, false)\nif err != nil && strings.Contains(fmt.Sprint(err), \"all asset mappings failed\") {\n\tfor _, r := range result.References { log.Printf(\"item failed: %v\", r) }\n\t// fix inputs and retry\n}","preventionTips":["Dry-run first and inspect per-item reasons","Verify each oldPath exists and is workspace-relative","Confirm the correct workspace/DataDir before batch operations"],"tags":["go","batch-operation","validation"],"backgroundTag":"empty-result-set","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"}