siyuan-note/siyuan · error

--file is required

Error message

--file is required

What it means

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.

Source

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

)

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
		}

		succMap, err := model.InsertLocalAssets(id, files, true)
		if err != nil {
			return err

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Add one or more --file flags: `asset upload --id <id> --file ./a.png --file ./b.png`
  2. If using a glob, verify it matched files before calling
  3. Check the exact flag name with `asset upload --help`

Example fix

# before
siyuan-kernel asset upload --id 20260605100657-v080a4j

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

Strategy: validation

Validate before calling

if len(files) == 0 { return errors.New("--file is required") }
// Or: assetUploadCmd.MarkFlagRequired("file")

Prevention

When it happens

Trigger: Running `siyuan-kernel asset upload --id <id>` with no --file flags, or all --file values empty.

Common situations: The user forgot the file argument; a glob in a script expanded to nothing; the flag was misnamed (e.g. --files instead of --file).

Related errors


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