{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/attr.go#L64-L100","documentation":"The `attr set` subcommand requires at least one `--attr name=value` flag to know which attributes to write. The handler counts the string-array `--attr` values and returns this error when none were supplied. It fires before any attribute is applied.","triggerScenarios":"Running `siyuan-kernel attr set --id 20260605100657-v080a4j` with no `--attr` flags at all.","commonSituations":"Intending to clear attributes but calling the command with only --id; writing a wrapper that forwards an empty attribute list; confusing attr set with a get command that needs no --attr.","solutions":["Pass at least one attribute: `--attr name=value` (repeatable, e.g. --attr icon=1f4ca --attr title-img=...)","If you meant to read attributes, use `attr batch-get --ids <id>` instead","In scripts, build the --attr list first and abort if it is empty"],"exampleFix":"// before\nsiyuan-kernel attr set --id 20260605100657-v080a4j\n// after\nsiyuan-kernel attr set --id 20260605100657-v080a4j --attr icon=1f4ca","handlingStrategy":"validation","validationCode":"ATTRS=(\"icon=1f4ca\")\nif [ ${#ATTRS[@]} -eq 0 ]; then echo \"--attr is required (format: name=value)\" >&2; exit 1; fi\nARGS=(); for a in \"${ATTRS[@]}\"; do ARGS+=(--attr \"$a\"); done\nsiyuan-kernel attr set --id \"$ID\" \"${ARGS[@]}\"","typeGuard":"function hasAttrs(flags) { return Array.isArray(flags) && flags.length > 0; }","tryCatchPattern":"if err := run(); err != nil && strings.Contains(err.Error(), \"--attr is required\") { // print usage hint about name=value }","preventionTips":["attr set is write-only; use batch-get for reading attributes","Build the --attr list programmatically and refuse to run when it is empty","Quote every --attr value containing spaces or =-bearing payloads"],"tags":["cli","required-flag","argument-validation"],"backgroundTag":"missing-required-flag","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"}