siyuan-note/siyuan · error

invalid attr format [ ], expected name=value

Error message

invalid attr format [%s], expected name=value

What it means

Each `--attr` value must contain an `=` separating attribute name from value; SplitN(a, "=", 2) must yield exactly two parts. When a supplied --attr string has no `=`, the handler rejects that specific string with this error, quoting the offending value. Values may themselves contain `=`; only the first `=` splits.

Solutions

  1. Write each attribute as name=value: `--attr icon=1f4ca`
  2. Quote flags containing spaces or special characters: `--attr 'title-img=background-image:url("assets/example.jpg")'`
  3. Check the error message's [%s] content — it names the exact malformed flag to fix

Example fix

// before
siyuan-kernel attr set --id 20260605100657-v080a4j --attr icon:1f4ca
// after
siyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca
Defensive patterns

Strategy: validation

Validate before calling

const ok = /^[^=]+=.+$/.test(attr); // true before passing --attr
if (!ok) throw new Error(`invalid attr format [${attr}], expected name=value`);

Type guard

function isNameValue(s) { return typeof s === "string" && s.includes("=") && s.split("=").length >= 2; }

Try / catch

if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), "invalid attr format") { // re-run with corrected flag }

Prevention

When it happens

Trigger: `siyuan-kernel attr set --id <id> --attr icon` (name only); `--attr "icon: 1f4ca"` using a colon from YAML habits; a quoted/escaped value where the shell stripped the `=`.

Common situations: Translating YAML frontmatter or HTTP headers into --attr flags and keeping the wrong separator; forgetting quotes so spaces split the flag into a second argument without `=`; JSON-style input like `--attr '{"icon":"1f4ca"}'`.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/a5f3111c86f959bc. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/attr.go:89

Examples:
  siyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca
  siyuan-kernel attr set --id 20260605100657-v080a4j --attr title-img='background-image:url("assets/example.jpg")'`,
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		if id == "" {
			return fmt.Errorf("--id is required")
		}

		attrFlags, _ := cmd.Flags().GetStringArray("attr")
		if len(attrFlags) == 0 {
			return fmt.Errorf("--attr is required (format: name=value)")
		}

		nameValues := make(map[string]string, len(attrFlags))
		for _, a := range attrFlags {
			parts := strings.SplitN(a, "=", 2)
			if len(parts) != 2 {
				return fmt.Errorf("invalid attr format [%s], expected name=value", a)
			}
			nameValues[strings.TrimSpace(parts[0])] = parts[1]
		}

		if dryRun {
			var parts []string
			for k, v := range nameValues {
				parts = append(parts, fmt.Sprintf("%s=%s", k, v))
			}
			fmt.Printf("[dry-run] Would set attributes on block %s: %s\n", id, strings.Join(parts, ", "))
			return nil
		}

		if err := model.SetBlockAttrs(id, nameValues); err != nil {
			return err
		}
		model.AppendPushReloadFiletreeEntry()
		fmt.Println("ok")

View on GitHub (pinned to 9f775e8a12)