{"record":{"id":"632fe73e00a38e69","repo":"siyuan-note/siyuan","slug":"av-key-item-and-value-are-required","errorCode":null,"errorMessage":"--av, --key, --item and --value are required","messagePattern":"--av, --key, --item and --value are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/database.go","lineNumber":318,"sourceCode":"\t\tif err := model.RemoveAttributeViewBlock(ids, avID); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},\n}\n\nvar databaseItemUpdateCmd = &cobra.Command{\n\tUse:   \"update --av <avID> --key <keyID> --item <itemID> --value <json>\",\n\tShort: \"Update a cell value\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tavID, _ := cmd.Flags().GetString(\"av\")\n\t\tkeyID, _ := cmd.Flags().GetString(\"key\")\n\t\titemID, _ := cmd.Flags().GetString(\"item\")\n\t\tvalueStr, _ := cmd.Flags().GetString(\"value\")\n\t\tif avID == \"\" || keyID == \"\" || itemID == \"\" || valueStr == \"\" {\n\t\t\treturn fmt.Errorf(\"--av, --key, --item and --value are required\")\n\t\t}\n\t\tvar valueData map[string]any\n\t\tif err := json.Unmarshal([]byte(valueStr), &valueData); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON: %s\", err)\n\t\t}\n\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would update cell in database %s: key=%s item=%s\\n\", avID, keyID, itemID)\n\t\t\treturn nil\n\t\t}\n\n\t\tif _, err := model.UpdateAttributeViewCell(nil, avID, keyID, itemID, valueData); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tmodel.AppendPushReloadAttrViewEntry(avID)\n\t\tfmt.Println(\"ok\")\n\t\treturn nil\n\t},","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/database.go#L300-L336","documentation":"The `database update` cobra subcommand requires four flags to be non-empty before it can update an Attribute View cell. The RunE handler reads --av, --key, --item, and --value via cmd.Flags().GetString and rejects the invocation if any of the four is the empty string. This is an argv-level guard that fires before any model.UpdateAttributeViewCell call, so the kernel never touches the database when a flag is missing.","triggerScenarios":"Invoking `siyuan database update` (or the long form) with any of --av <avID>, --key <keyID>, --item <itemID>, or --value <json> omitted, left empty (e.g. `--av \"\"`), or misspelled so the flag is never registered. It also fires if the flags are entirely absent because the user expected positional arguments.","commonSituations":"Copy-pasting a command template and forgetting to fill one placeholder; assuming --value is optional for clearing a cell; mistyping `--item` as `--itemid`; running the command interactively and pressing enter on an empty prompt; scripting the call and passing an unset shell variable that expands to empty.","solutions":["Re-run the command supplying all four flags: `database update --av <avID> --key <keyID> --item <itemID> --value '<json>'`.","Confirm the exact flag names with `siyuan database update --help`; the Use string lists the canonical names.","If scripting, guard each variable before invoking: abort with a clear message when any of avID/keyID/itemID/valueStr is empty.","Remember --value must be present even to clear a cell — pass an explicit empty-object payload the model accepts rather than omitting the flag."],"exampleFix":"// before\nsiyuan database update --av 20240101000000-abc --key k1 --item i1\n// after\nsiyuan database update --av 20240101000000-abc --key k1 --item i1 --value '{\"text\":\"hello\"}'","handlingStrategy":"validation","validationCode":"# shell: assert all four flags before invoking\n[ -n \"$AV\" ] && [ -n \"$KEY\" ] && [ -n \"$ITEM\" ] && [ -n \"$VALUE\" ] || { echo 'missing --av/--key/--item/--value' >&2; exit 2; }\nsiyuan database update --av \"$AV\" --key \"$KEY\" --item \"$ITEM\" --value \"$VALUE\"","typeGuard":"// Go (programmatic caller of the RunE equivalent): guard before calling model.UpdateAttributeViewCell\nfunc hasAllUpdateInputs(avID, keyID, itemID, valueStr string) bool {\n\treturn avID != \"\" && keyID != \"\" && itemID != \"\" && valueStr != \"\"\n}","tryCatchPattern":"# CLI callers propagate the non-zero exit; inspect stderr\nif ! siyuan database update --av \"$AV\" --key \"$KEY\" --item \"$ITEM\" --value \"$VALUE\"; then\n  echo \"update failed; check flags\" >&2\n  exit 1\nfi","preventionTips":["Define a shell wrapper function that requires all four variables and exits early.","Use `set -u` so referencing an unset variable aborts the script.","Pin the canonical flag set with a usage string in your runbook."],"tags":["cli","cobra","flag-validation","attribute-view","database","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}