{"record":{"id":"f570ce0f893b7d4c","repo":"siyuan-note/siyuan","slug":"assetpath-is-required-for-analyze","errorCode":null,"errorMessage":"assetPath is required for analyze","messagePattern":"assetPath is required for analyze","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":455,"sourceCode":"\t\treturn DocumentImageList{}, fmt.Errorf(\"list document images failed: %w\", err)\n\t}\n\trefs := make([]ImageArtifactRef, 0, len(paths))\n\tseen := map[string]bool{}\n\tfor _, assetPath := range paths {\n\t\tif !strings.HasPrefix(AssetPathWithoutQuery(assetPath), \"assets/\") || seen[assetPath] {\n\t\t\tcontinue\n\t\t}\n\t\tseen[assetPath] = true\n\t\trefs = append(refs, ImageArtifactRef{Kind: \"image\", Path: assetPath, DocumentID: bt.RootID})\n\t}\n\treturn DocumentImageList{DocumentID: bt.RootID, Images: refs}, nil\n}\n\n// PrepareDocumentImage 校验并读取文档实际引用的本地资源图片，供当前模型直接接收图片输入。\nfunc PrepareDocumentImage(documentID, assetPath string) (PreparedDocumentImage, error) {\n\tassetPath = strings.TrimSpace(assetPath)\n\tif assetPath == \"\" {\n\t\treturn PreparedDocumentImage{}, errors.New(\"assetPath is required for analyze\")\n\t}\n\tif !strings.HasPrefix(AssetPathWithoutQuery(assetPath), \"assets/\") {\n\t\treturn PreparedDocumentImage{}, errors.New(\"only local assets/... images are supported\")\n\t}\n\tbt, err := resolveMultimodalDocument(documentID)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\tif !documentReferencesImage(bt.RootID, assetPath) {\n\t\treturn PreparedDocumentImage{}, errors.New(\"assetPath is not an image referenced by the document\")\n\t}\n\tdata, err := ReadAssetBytesInBox(bt.BoxID, assetPath)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, fmt.Errorf(\"read image failed: %w\", err)\n\t}\n\tprepared, err := util.PrepareModelImage(\n\t\tdata, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,\n\t)","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/assets.go#L437-L473","documentation":"Validation guard in PrepareDocumentImage: fires when the assetPath argument is empty. Analyzing a document image requires a concrete asset path under assets/ to resolve and read; calling imageAnalyze (or the function directly, as tests do) without a path is the faulting input, distinct from later network-image rejection.","triggerScenarios":"Calling imageAnalyze / PrepareDocumentImage with assetPath omitted or set to \"\" or \"   \".","commonSituations":"Client code reading the path from config or a form field that was left blank; forgetting to pass the field when building the JSON request body.","solutions":["Populate assetPath with a document-referenced assets/... path before calling","Trim and check the value on the client and show a validation message instead of sending the request","Default the UI picker so it always supplies the currently selected image path"],"exampleFix":"// before\nPrepareDocumentImage(docID, \"\")\n// after\nif assetPath == \"\" { return errors.New(\"choose an image first\") }\nPrepareDocumentImage(docID, assetPath)","handlingStrategy":"validation","validationCode":"if strings.TrimSpace(assetPath) == \"\" { return errors.New(\"assetPath is required\") }","typeGuard":null,"tryCatchPattern":"prepared, err := PrepareDocumentImage(docID, assetPath)\nif err != nil && strings.Contains(err.Error(), \"assetPath is required\") { return userFacingError(\"select an image first\") }","preventionTips":["Always source assetPath from the document image list, not from optional config","Validate required request fields in the API layer before reaching the kernel","Trim whitespace client-side and reject empty submissions"],"tags":["go","validation","missing-argument","ai"],"backgroundTag":"missing-required-argument","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"}