{"record":{"id":"4ed2604935a9960c","repo":"FiloSottile/age","slug":"malformed-file-key-stanza-unexpected-arguments-co","errorCode":null,"errorMessage":"malformed file-key stanza: unexpected arguments count","messagePattern":"malformed file-key stanza: unexpected arguments count","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/client.go","lineNumber":270,"sourceCode":"\t\t}\n\t}\n\tif err := writeStanza(conn, \"done\"); err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Phase 2: plugin responds with various commands and a file key\n\tsr := format.NewStanzaReader(bufio.NewReader(conn))\nReadLoop:\n\tfor {\n\t\ts, err := i.ui.readStanza(i.name, sr)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tswitch s.Type {\n\t\tcase \"file-key\":\n\t\t\tif len(s.Args) != 1 {\n\t\t\t\treturn nil, fmt.Errorf(\"malformed file-key stanza: unexpected arguments 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, fmt.Errorf(\"malformed file-key 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, fmt.Errorf(\"malformed file-key stanza: unexpected index\")\n\t\t\t}\n\t\t\tif fileKey != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"received duplicated file-key stanza\")\n\t\t\t}\n\n\t\t\tfileKey = s.Body\n\n\t\t\tif err := writeStanza(conn, \"ok\"); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/FiloSottile/age/blob/b74dce4cdbe35b5e5f66c06d9612b72f89028758/plugin/client.go#L252-L288","documentation":"During age plugin unwrapping, the client parses a 'file-key' stanza sent by the plugin binary. This error means the stanza carried a number of arguments other than exactly one (the file-key index). The age plugin protocol v1 requires the file-key stanza to have exactly one argument, so the client rejects anything else as a protocol violation.","triggerScenarios":"A plugin binary writes a 'file-key' stanza with zero or two or more space-separated arguments (e.g. writeStanza(conn, \"file-key\", args...) called with wrong arity) while the client's Unwrap/UnwrapWithLabels is reading its response.","commonSituations":"Custom or third-party age plugins that hand-roll the plugin protocol and emit a malformed file-key stanza; plugin versions that predate or diverge from the v1 protocol; a plugin binary on PATH that is actually a different/older program responding with an unexpected format.","solutions":["Update the plugin binary to a version that conforms to the age-plugin protocol v1 (exactly one argument in the file-key stanza)","Check which plugin binary is being resolved for AGE-PLUGIN-<name>-1 identities (age-plugin-<name> on PATH / testOnlyPluginPath) and remove shadowing scripts","If you wrote the plugin, fix its Unwrap loop to send writeStanza(w, \"file-key\", \"0\") with a single argument","Verify the recipient/identity stanza name matches the plugin actually handling it; a mismatched plugin may answer with stanzas it shouldn't"],"exampleFix":"// before (plugin side)\nwriteStanza(w, \"file-key\", \"0\", \"extra\")\n// after\nwriteStanza(w, \"file-key\", \"0\")","handlingStrategy":"validation","validationCode":"// Client can't pre-validate plugin output; validate the plugin before use.\nout, err := exec.Command(\"age-plugin-foo\", \"--age-plugin=recipient-v1\").Output()\nif err != nil { log.Fatalf(\"plugin broken: %v\", err) }","typeGuard":null,"tryCatchPattern":"if _, err := identity.Unwrap(...); err != nil {\n    if strings.Contains(err.Error(), \"malformed file-key stanza\") {\n        // treat plugin as incompatible: report version, suggest upgrade\n    }\n}","preventionTips":["Keep plugin binaries updated to spec-conforming versions","Test plugins with the age-plugin-test-tool suite","Pin plugin versions; avoid shadowing scripts on PATH"],"tags":["go","age","plugin-protocol","stanza-parsing"],"backgroundTag":"plugin-protocol-violation","analyzedSha":"b74dce4cdbe35b5e5f66c06d9612b72f89028758","analyzedAt":"2026-08-31T23:59:31.627Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}