{"record":{"id":"c9bf524a96c76f05","repo":"siyuan-note/siyuan","slug":"attr-is-required-format-name-value","errorCode":null,"errorMessage":"--attr is required (format: name=value)","messagePattern":"--attr is required \\(format: name=value\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/attr.go","lineNumber":82,"sourceCode":"Common attributes:\n  icon       Emoji hex codepoint (e.g. \"1f4ca\"), emoji character (e.g. \"📊\"), custom image path (e.g. \"1/b3log.png\"), network image URL (e.g.\n             \"https://example.com/icon.png\"), or dynamic icon URL (e.g. \"api/icon/getDynamicIcon?type=8&color=%23d23f31&content=SiYuan&id=xxx\").\n  title-img  CSS background-image format (e.g. 'background-image:url(\"assets/example.jpg\")').\n             DO NOT use a bare asset path.\n  tags       Comma-separated tag names.\n\nExamples:\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","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/attr.go#L64-L100","documentation":"Thrown by the `attr set` cobra subcommand when the `--attr` flag (a StringArray) is absent or empty. The command requires at least one `name=value` pair to know which block attribute to write. It is a pure argument-guard: the model layer is never reached.","triggerScenarios":"Running `siyuan-kernel attr set --id <blockID>` without any `--attr` flag, or passing `--attr` with zero values. The check is `len(attrFlags) == 0` on the resolved StringArray.","commonSituations":"Forgetting the `--attr` argument when scripting attribute updates; copy-pasting the example from `--help` but dropping the attribute portion; expecting attributes to be read from stdin.","solutions":["Add at least one `--attr name=value`, e.g. `siyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca`","For multiple attributes repeat the flag: `--attr icon=1f4ca --attr title-img='background-image:url(\"x.jpg\")'`","Run `siyuan-kernel attr set --help` to confirm the exact flag spelling and the `name=value` format"],"exampleFix":"// before\nsiyuan-kernel attr set --id 20260605100657-v080a4j\n// after\nsiyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca","handlingStrategy":"validation","validationCode":"// Before invoking the CLI in a script, assert the attr payload is non-empty.\nattrs := []string{\"icon=1f4ca\"} // built by your script\nif len(attrs) == 0 {\n    return fmt.Errorf(\"refusing to run: no --attr values provided\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap CLI invocations in a helper that requires `--attr` programmatically before exec","Keep a single source of truth for the attributes map and assert it is non-empty","Always pass `--id` and `--attr` together; treat them as an atomic pair"],"tags":["cli","attr","argument-validation","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}