{"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":47,"sourceCode":")\n\nvar assetCmd = &cobra.Command{\n\tUse:   \"asset\",\n\tShort: \"Manage assets\",\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\tsuccMap, err := model.InsertLocalAssets(id, files, true)\n\t\tif err != nil {\n\t\t\treturn err","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/asset.go#L29-L65","documentation":"The `asset upload` subcommand requires at least one --file flag but none were supplied. Thrown by assetUploadCmd.RunE at kernel/cli/cmd/asset.go:45-47. --file is a repeatable StringArray flag; an empty slice means nothing to upload.","triggerScenarios":"Running `siyuan-kernel asset upload --id <id>` with no --file flags, or all --file values empty.","commonSituations":"The user forgot the file argument; a glob in a script expanded to nothing; the flag was misnamed (e.g. --files instead of --file).","solutions":["Add one or more --file flags: `asset upload --id <id> --file ./a.png --file ./b.png`","If using a glob, verify it matched files before calling","Check the exact flag name with `asset upload --help`"],"exampleFix":"# before\nsiyuan-kernel asset upload --id 20260605100657-v080a4j\n\n# after\nsiyuan-kernel asset upload --id 20260605100657-v080a4j --file ./x.png","handlingStrategy":"validation","validationCode":"if len(files) == 0 { return errors.New(\"--file is required\") }\n// Or: assetUploadCmd.MarkFlagRequired(\"file\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark --file required via cobra so cobra emits a usage error automatically","Verify globs expand to files before passing them to the CLI","Use the exact flag name --file (not --files)"],"tags":["cli","asset","validation","cobra","flags"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}