{"record":{"id":"a676f8cca6a44f0b","repo":"FiloSottile/age","slug":"malformed-recipient-stanza-unexpected-argument-co","errorCode":null,"errorMessage":"malformed recipient stanza: unexpected argument count","messagePattern":"malformed recipient stanza: unexpected argument count","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/client.go","lineNumber":117,"sourceCode":"\t\treturn nil, nil, err\n\t}\n\tif err := writeStanza(conn, \"done\"); err != nil {\n\t\treturn nil, nil, err\n\t}\n\n\t// Phase 2: plugin responds with stanzas\n\tsr := format.NewStanzaReader(bufio.NewReader(conn))\nReadLoop:\n\tfor {\n\t\ts, err := r.ui.readStanza(r.name, sr)\n\t\tif err != nil {\n\t\t\treturn nil, nil, err\n\t\t}\n\n\t\tswitch s.Type {\n\t\tcase \"recipient-stanza\":\n\t\t\tif len(s.Args) < 2 {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"malformed recipient stanza: unexpected argument count\")\n\t\t\t}\n\t\t\tn, err := strconv.Atoi(s.Args[0])\n\t\t\tif err != nil {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"malformed recipient stanza: invalid index\")\n\t\t\t}\n\t\t\t// We only send a single file key, so the index must be 0.\n\t\t\tif n != 0 {\n\t\t\t\treturn nil, nil, fmt.Errorf(\"malformed recipient stanza: unexpected index\")\n\t\t\t}\n\n\t\t\tstanzas = append(stanzas, &age.Stanza{\n\t\t\t\tType: s.Args[1],\n\t\t\t\tArgs: s.Args[2:],\n\t\t\t\tBody: s.Body,\n\t\t\t})\n\n\t\t\tif err := writeStanza(conn, \"ok\"); err != nil {\n\t\t\t\treturn nil, nil, err","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/FiloSottile/age/blob/b74dce4cdbe35b5e5f66c06d9612b72f89028758/plugin/client.go#L99-L135","documentation":"The client received a 'recipient-stanza' from the plugin whose Args slice has fewer than 2 elements. The recipient-v1 protocol requires Args[0] to be the file-key index and Args[1] to be the stanza type, so a short stanza is treated as a protocol violation by the plugin.","triggerScenarios":"Calling WrapWithLabels/Wrap against a plugin that emits a recipient-stanza with missing arguments, i.e. a buggy, outdated, or non-conformant plugin speaking the recipient-v1 protocol incorrectly.","commonSituations":"Running an old plugin version that predates the index-argument convention; a hand-written third-party plugin with a protocol bug; garbled plugin response due to IO issues; testing a plugin under development that writes malformed stanzas.","solutions":["Upgrade the plugin to the latest version so it emits recipient stanzas as '<index> <type> [args...]'.","If you develop the plugin, fix the writer to send at least two args (index then stanza type).","Capture the raw stanza with debug logging to confirm which side is malformed.","Report the bug to the plugin maintainer if it is third-party code."],"exampleFix":"// before (plugin side, buggy)\nwriteStanza(conn, \"recipient-stanza\", stanzaType) // missing index\n// after\nwriteStanza(conn, \"recipient-stanza\", \"0\", stanzaType, extraArgs...)","handlingStrategy":"validation","validationCode":"// Go: validate recipient-stanza args before processing if you implement a plugin client\ntype Stanza struct{ Type string; Args []string; Body []byte }\nfunc validRecipientStanza(s Stanza) bool {\n    return s.Type == \"recipient-stanza\" && len(s.Args) >= 2\n}","typeGuard":"func isRecipientStanzaWithArgs(s Stanza) bool {\n    return s.Type == \"recipient-stanza\" && len(s.Args) >= 2\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"malformed recipient stanza\") {\n        return fmt.Errorf(\"plugin not conformant with recipient-v1; upgrade the plugin: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep plugins updated to the current protocol version.","Test custom plugins against the age plugin test suite before shipping.","Log raw plugin transcripts during development to catch argument layout mistakes early.","Pin known-good plugin versions in production."],"tags":["go","age","plugin","protocol","malformed-data"],"backgroundTag":"plugin-protocol-violation","analyzedSha":"b74dce4cdbe35b5e5f66c06d9612b72f89028758","analyzedAt":"2026-08-31T23:59:31.627Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}