{"record":{"id":"0590be2281b5af8a","repo":"siyuan-note/siyuan","slug":"file-is-required","errorCode":null,"errorMessage":"--file is required","messagePattern":"--file is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/asset.go","lineNumber":82,"sourceCode":"\t}\n\tfor _, item := range result.Failed {\n\t\tfmt.Fprintf(w, \"failed\\t%s\\t\\t%s\\n\", item.Name, item.Error)\n\t}\n\tw.Flush()\n}\n\nvar assetUploadCmd = &cobra.Command{\n\tUse:   \"upload --id <id> --file <path>\",\n\tShort: \"Upload files to workspace assets\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\n\t\tfiles, _ := cmd.Flags().GetStringArray(\"file\")\n\t\tif len(files) == 0 {\n\t\t\treturn fmt.Errorf(\"--file is required\")\n\t\t}\n\n\t\tfor i, f := range files {\n\t\t\tabs, err := filepath.Abs(f)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tfiles[i] = abs\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would upload %d file(s) to document %s\\n\", len(files), id)\n\t\t\treturn nil\n\t\t}\n\n\t\t_, succFiles, failedFiles, err := model.InsertLocalAssets(id, files, true)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/asset.go#L64-L100","documentation":"Argument validation in the cobra assetUpload RunE: fires when no --file flag value was supplied. Upload needs at least one file path to copy into the workspace assets directory; invoking `asset upload` with only --id (or with no flags) is the faulting usage.","triggerScenarios":"Running `asset upload --id <id>` with no --file flags, or `--file \"\"` only.","commonSituations":"Building the command programmatically from a file list that ended up empty; forgetting that --file is repeatable and supplying none.","solutions":["Add one or more --file flags: `asset upload --id <id> --file <path> [--file <path2> ...]`.","Verify the source list/glob actually produced file paths before invoking the CLI.","Check the paths exist and are readable."],"exampleFix":"// before\nsiyuan asset upload --id 20240101120000-abcdefg\n// after\nsiyuan asset upload --id 20240101120000-abcdefg --file ./img.png","handlingStrategy":"validation","validationCode":"if [ ${#FILES[@]} -eq 0 ]; then echo \"no files to upload\"; exit 1; fi\nARGS=(); for f in \"${FILES[@]}\"; do ARGS+=(--file \"$f\"); done\nsiyuan asset upload --id \"$BLOCK_ID\" \"${ARGS[@]}\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure the file list/glob is non-empty before building the command.","Remember --file is repeatable; pass one flag per file."],"tags":["cli","validation"],"backgroundTag":"missing-required-flag","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"}