siyuan-note/siyuan · error

--path must not be empty

Error message

--path must not be empty

What it means

The `asset clean` subcommand had its --path flag explicitly set (cmd.Flags().Changed("path") is true) but the value is empty. Thrown at kernel/cli/cmd/asset.go:115-117. Without --path the command cleans all unused assets, so an explicit empty value is treated as a mistake rather than the bulk mode.

Source

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

			fmt.Fprintln(w, "PATH\tNAME")
			for _, item := range items {
				fmt.Fprintf(w, "%s\t%s\n", item.Item, item.Name)
			}
			w.Flush()
			fmt.Printf("\n%d unused asset(s)\n", len(items))
		}
		return nil
	},
}

var assetCleanCmd = &cobra.Command{
	Use:   "clean",
	Short: "Clean unused assets",
	RunE: func(cmd *cobra.Command, args []string) error {
		singlePath, _ := cmd.Flags().GetString("path")
		if cmd.Flags().Changed("path") {
			if singlePath == "" {
				return fmt.Errorf("--path must not be empty")
			}
			if dryRun {
				relativePath, _, err := model.ResolveUnusedDataAssetPath(singlePath)
				if err != nil {
					return err
				}
				fmt.Printf("[dry-run] Would remove unused asset: %s\n", relativePath)
				return nil
			}
			ret, err := model.RemoveUnusedAsset(singlePath)
			if err != nil {
				return err
			}
			fmt.Println(ret)
			return nil
		}

		if dryRun {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Drop the --path flag entirely to clean all unused assets: `asset clean`
  2. Or supply a concrete unused-asset path: `asset clean --path assets/image/x.png`
  3. If scripting, only add --path when the variable is non-empty

Example fix

# before (explicit empty)
siyuan-kernel asset clean --path ""

# after (bulk clean — omit the flag entirely)
siyuan-kernel asset clean
Defensive patterns

Strategy: validation

Validate before calling

// Only include --path when it has a value
args := []string{"asset","clean"}
if p != "" { args = append(args, "--path", p) }

Prevention

When it happens

Trigger: Running `siyuan-kernel asset clean --path ""` or `--path=` or `--path "$EMPTYVAR"` where the variable expanded to empty.

Common situations: A shell variable for the path was unset or empty; the user passed --path intending bulk clean but the flag requires a concrete value when present.

Related errors


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