siyuan-note/siyuan · error
invalid attr format [%s], expected name=value
Error message
invalid attr format [%s], expected name=value
What it means
Thrown inside the `attr set` loop that parses each `--attr` entry with `strings.SplitN(a, "=", 2)`. If an entry has no `=` separator, `SplitN` returns a one-element slice and the guard `len(parts) != 2` rejects it. The offending raw value is interpolated so the user sees exactly which token failed.
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 251596fc0d)
Solutions
- Rewrite the token as `name=value`, e.g. `--attr icon=1f4ca`
- If the value contains `=`, that is fine — only the FIRST `=` is the separator (SplitN limit 2)
- Quote values with spaces: `--attr title-img='background-image:url("a.jpg")'`
- Inspect the bracketed token in the message to see which entry failed
Example fix
// before siyuan-kernel attr set --id <id> --attr icon // after siyuan-kernel attr set --id <id> --attr icon=1f4ca
Defensive patterns
Strategy: validation
Validate before calling
// Validate each name=value token before passing it to the CLI.
for _, a := range attrTokens {
if !strings.Contains(a, "=") {
return fmt.Errorf("attr token %q lacks '=' separator", a)
}
} Prevention
- Always construct `--attr` tokens as `name=value` in code, never by concatenation that may drop the `=`
- Quote values containing spaces or special characters
- Surface the failed token to the user so they can correct the specific entry
When it happens
Trigger: Passing `--attr icon` (no `=`), `--attr =val` or `--attr key` without a value. Any token that does not contain at least one `=` sign triggers it.
Common situations: Using a space instead of `=`; quoting the whole flag so the shell strips the `=`; passing a flag-style value like `--attr --icon`; mistakenly thinking the flag takes a key only.
Related errors
- --attr is required (format: name=value)
- --ids is required
- --id is required
- --id is required
- document not found or empty
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/a5f3111c86f959bc.
Report an issue: GitHub.