{"record":{"id":"6949ab89fe58aa8c","repo":"FiloSottile/age","slug":"failed-to-write-error-stanza-v","errorCode":null,"errorMessage":"failed to write error stanza: %v","messagePattern":"failed to write error stanza: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/plugin.go","lineNumber":673,"sourceCode":"\t}\n}\n\nfunc expectUnsupported(sr *format.StanzaReader) error {\n\tunsupported, err := sr.ReadStanza()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read unsupported stanza: %v\", err)\n\t}\n\tif unsupported.Type != \"unsupported\" {\n\t\treturn fmt.Errorf(\"expected unsupported stanza, got %q\", unsupported.Type)\n\t}\n\treturn expectStanzaWithNoBody(unsupported, 0)\n}\n\nfunc (p *Plugin) writeError(args []string, err error) error {\n\ts := &format.Stanza{Type: \"error\", Args: args}\n\ts.Body = []byte(err.Error())\n\tif err := s.Marshal(p.stdout); err != nil {\n\t\treturn fmt.Errorf(\"failed to write error stanza: %v\", err)\n\t}\n\tif err := expectOk(p.sr); err != nil {\n\t\treturn fmt.Errorf(\"%v\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":655,"sourceCodeEnd":680,"githubUrl":"https://github.com/FiloSottile/age/blob/b74dce4cdbe35b5e5f66c06d9612b72f89028758/plugin/plugin.go#L655-L680","documentation":"writeError formats an error stanza (Type \"error\", with the error text as the body) and writes it to the plugin's stdout. This message wraps a failure of Stanza.Marshal on that write — i.e. the error stanza itself could not be serialized or written to stdout, typically due to an underlying I/O failure on the output pipe.","triggerScenarios":"Plugin.IdentityV1, recipientError, or identityError call writeError when the original operation failed; the Marshal call to p.stdout then fails (broken/closed stdout pipe, output stream error).","commonSituations":"Parent age process closed its end of the pipe or crashed mid-protocol; stdout redirected to a full disk or closed file descriptor; running the plugin binary in an environment without a connected stdout.","solutions":["Check the wrapped %v detail for the underlying write error (EPIPE, EBADF, etc.).","Ensure the invoking age process keeps stdout/stdin pipes open for the plugin's lifetime.","Verify the plugin is invoked as a plugin (with piped stdio), not run interactively with a closed stdout.","Check disk space / file descriptor limits if stdout is redirected to a file."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := runPlugin(); err != nil {\n    var syscallErr *os.SyscallError\n    if errors.As(err, &syscallErr) && errors.Is(syscallErr.Err, syscall.EPIPE) {\n        // parent process gone; abort quietly\n    }\n}","preventionTips":["Never close the age process's stdin/stdout pipes before the plugin finishes.","Run plugins through the age binary rather than invoking them interactively.","Monitor wrapped write errors (EPIPE/EBADF) to detect premature parent exit."],"tags":["go","io","plugin","stdout"],"backgroundTag":"broken-pipe-stdout","analyzedSha":"b74dce4cdbe35b5e5f66c06d9612b72f89028758","analyzedAt":"2026-08-31T23:59:31.627Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}