{"record":{"id":"e6694d668b099181","repo":"siyuan-note/siyuan","slug":"id-is-required","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/asset.go","lineNumber":42,"sourceCode":"\t\"text/tabwriter\"\n\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\n\t\"github.com/spf13/cobra\"\n)\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","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/asset.go#L24-L60","documentation":"The `asset upload` subcommand requires the --id flag (target document block ID) but it was empty or omitted. Thrown by assetUploadCmd.RunE at kernel/cli/cmd/asset.go:40-42. The flag is declared with an empty default in init() and is not marked required via cobra, so this manual check enforces presence.","triggerScenarios":"Running `siyuan-kernel asset upload` without --id, or passing --id with an empty value (e.g. --id \"\" or an unset shell variable).","commonSituations":"Script/CI invocation forgot the flag; a shell variable expanded to empty; the user copied a command template and left the placeholder blank.","solutions":["Pass the target document block ID: `asset upload --id 20260605100657-v080a4j --file ./x.png`","If scripting, guard that the ID variable is non-empty before invoking","Use `asset upload --help` to confirm flag names and required values"],"exampleFix":"# before\nsiyuan-kernel asset upload --file ./x.png\n\n# after\nsiyuan-kernel asset upload --id 20260605100657-v080a4j --file ./x.png","handlingStrategy":"validation","validationCode":"// In Go caller code, check before invoking cobra\nif id == \"\" { return errors.New(\"--id is required\") }\n// Or enforce via cobra itself:\n// assetUploadCmd.MarkFlagRequired(\"id\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark the flag required in cobra (MarkFlagRequired) so misuse is caught with a standard usage error","In scripts, assert the ID variable is non-empty before invoking the CLI","Keep a documented example command in the help text"],"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"}