siyuan-note/siyuan · error

--id is required

Error message

--id is required

What it means

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.

Source

Thrown at kernel/cli/cmd/asset.go:42

	"text/tabwriter"

	"github.com/siyuan-note/siyuan/kernel/model"

	"github.com/spf13/cobra"
)

var assetCmd = &cobra.Command{
	Use:   "asset",
	Short: "Manage assets",
}

var assetUploadCmd = &cobra.Command{
	Use:   "upload --id <id> --file <path>",
	Short: "Upload files to workspace assets",
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		if id == "" {
			return fmt.Errorf("--id is required")
		}

		files, _ := cmd.Flags().GetStringArray("file")
		if len(files) == 0 {
			return fmt.Errorf("--file is required")
		}

		for i, f := range files {
			abs, err := filepath.Abs(f)
			if err != nil {
				return err
			}
			files[i] = abs
		}

		if dryRun {
			fmt.Printf("[dry-run] Would upload %d file(s) to document %s\n", len(files), id)
			return nil

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Pass the target document block ID: `asset upload --id 20260605100657-v080a4j --file ./x.png`
  2. If scripting, guard that the ID variable is non-empty before invoking
  3. Use `asset upload --help` to confirm flag names and required values

Example fix

# before
siyuan-kernel asset upload --file ./x.png

# after
siyuan-kernel asset upload --id 20260605100657-v080a4j --file ./x.png
Defensive patterns

Strategy: validation

Validate before calling

// In Go caller code, check before invoking cobra
if id == "" { return errors.New("--id is required") }
// Or enforce via cobra itself:
// assetUploadCmd.MarkFlagRequired("id")

Prevention

When it happens

Trigger: Running `siyuan-kernel asset upload` without --id, or passing --id with an empty value (e.g. --id "" or an unset shell variable).

Common situations: Script/CI invocation forgot the flag; a shell variable expanded to empty; the user copied a command template and left the placeholder blank.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/e6694d668b099181. Report an issue: GitHub.