{"record":{"id":"a5f3111c86f959bc","repo":"siyuan-note/siyuan","slug":"invalid-attr-format-s-expected-name-value","errorCode":null,"errorMessage":"invalid attr format [%s], expected name=value","messagePattern":"invalid attr format \\[(.+?)\\], expected name=value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/attr.go","lineNumber":89,"sourceCode":"Examples:\n  siyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca\n  siyuan-kernel attr set --id 20260605100657-v080a4j --attr title-img='background-image:url(\"assets/example.jpg\")'`,\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\n\t\tattrFlags, _ := cmd.Flags().GetStringArray(\"attr\")\n\t\tif len(attrFlags) == 0 {\n\t\t\treturn fmt.Errorf(\"--attr is required (format: name=value)\")\n\t\t}\n\n\t\tnameValues := make(map[string]string, len(attrFlags))\n\t\tfor _, a := range attrFlags {\n\t\t\tparts := strings.SplitN(a, \"=\", 2)\n\t\t\tif len(parts) != 2 {\n\t\t\t\treturn fmt.Errorf(\"invalid attr format [%s], expected name=value\", a)\n\t\t\t}\n\t\t\tnameValues[strings.TrimSpace(parts[0])] = parts[1]\n\t\t}\n\n\t\tif dryRun {\n\t\t\tvar parts []string\n\t\t\tfor k, v := range nameValues {\n\t\t\t\tparts = append(parts, fmt.Sprintf(\"%s=%s\", k, v))\n\t\t\t}\n\t\t\tfmt.Printf(\"[dry-run] Would set attributes on block %s: %s\\n\", id, strings.Join(parts, \", \"))\n\t\t\treturn nil\n\t\t}\n\n\t\tif err := model.SetBlockAttrs(id, nameValues); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadFiletreeEntry()\n\t\tfmt.Println(\"ok\")","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/attr.go#L71-L107","documentation":"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.","triggerScenarios":"`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 `=`.","commonSituations":"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\"}'`.","solutions":["Write each attribute as name=value: `--attr icon=1f4ca`","Quote flags containing spaces or special characters: `--attr 'title-img=background-image:url(\"assets/example.jpg\")'`","Check the error message's [%s] content — it names the exact malformed flag to fix"],"exampleFix":"// before\nsiyuan-kernel attr set --id 20260605100657-v080a4j --attr icon:1f4ca\n// after\nsiyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca","handlingStrategy":"validation","validationCode":"const ok = /^[^=]+=.+$/.test(attr); // true before passing --attr\nif (!ok) throw new Error(`invalid attr format [${attr}], expected name=value`);","typeGuard":"function isNameValue(s) { return typeof s === \"string\" && s.includes(\"=\") && s.split(\"=\").length >= 2; }","tryCatchPattern":"if err := cmd.Execute(); err != nil && strings.Contains(err.Error(), \"invalid attr format\") { // re-run with corrected flag }","preventionTips":["Use name=value with an equals sign, never YAML colons or JSON braces","Quote --attr values: --attr 'title-img=background-image:url(...)'","Only the first = splits, so values may contain additional = signs safely"],"tags":["cli","argument-format","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}