{"record":{"id":"d77dc5ba3cb85dd6","repo":"d2lang/d2","slug":"v-stderr-s","errorCode":null,"errorMessage":"%v\nstderr:\n%s","messagePattern":"(.+?)\nstderr:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"d2plugin/exec.go","lineNumber":58,"sourceCode":"// If any errors occur the binary will exit with a non zero status code and write\n// the error to stderr.\ntype execPlugin struct {\n\tpath string\n\topts map[string]string\n\tinfo *PluginInfo\n}\n\nfunc (p *execPlugin) Flags(ctx context.Context) (_ []PluginSpecificFlag, err error) {\n\tctx, cancel := context.WithTimeout(ctx, time.Second*10)\n\tdefer cancel()\n\tcmd := exec.CommandContext(ctx, p.path, \"flags\")\n\tdefer xdefer.Errorf(&err, \"failed to run %v\", cmd.Args)\n\n\tstdout, err := cmd.Output()\n\tif err != nil {\n\t\tee := &exec.ExitError{}\n\t\tif errors.As(err, &ee) && len(ee.Stderr) > 0 {\n\t\t\treturn nil, fmt.Errorf(\"%v\\nstderr:\\n%s\", ee, ee.Stderr)\n\t\t}\n\t\treturn nil, err\n\t}\n\n\tvar flags []PluginSpecificFlag\n\n\terr = json.Unmarshal(stdout, &flags)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal json: %w\", err)\n\t}\n\n\treturn flags, nil\n}\n\nfunc (p *execPlugin) HydrateOpts(opts []byte) error {\n\tif opts != nil {\n\t\tvar execOpts map[string]interface{}\n\t\terr := json.Unmarshal(opts, &execOpts)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/d2lang/d2/blob/0d69dca6f532ceaeacd615d35d1eaa41a238ffdb/d2plugin/exec.go#L40-L76","documentation":"execPlugin.Flags runs a compiled d2 plugin binary with the flags subcommand. If the binary exits non-zero and wrote to stderr, the error combines the exec.ExitError with the plugin's stderr so the plugin's own diagnostic is surfaced.","triggerScenarios":"Calling plugin.Flags() when the plugin binary fails during flag discovery — bad plugin version, plugin crashing on startup, or plugin rejecting a CLI argument.","commonSituations":"Stale or incompatible d2 plugin binary on PATH; plugin built against a different d2plugin protocol; missing runtime deps for the plugin.","solutions":["Read the stderr portion of the error — it contains the plugin's own failure message","Rebuild/reinstall the plugin with `d2 plugin install` matching your d2 version","Run the plugin binary manually with its flags subcommand to reproduce","Verify the plugin path in d2 config points to the right binary"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure plugin binary exists and is runnable before use\nif _, err := os.Stat(pluginPath); err != nil {\n    return fmt.Errorf(\"plugin binary missing: %w\", err)\n}\ncmd := exec.Command(pluginPath, \"version\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"plugin not executable: %w\", err)\n}","typeGuard":"func hasPluginStderr(err error) bool {\n    return strings.Contains(err.Error(), \"\\nstderr:\\n\")\n}","tryCatchPattern":"flags, err := plugin.Flags()\nif err != nil {\n    if strings.Contains(err.Error(), \"stderr:\") {\n        log.Fatalf(\"plugin crashed: %v\", err) // stderr details included\n    }\n    return err\n}","preventionTips":["Keep plugin binaries in sync with your d2 version","Reinstall plugins after upgrading d2 (d2 plugin install)","Smoke-test plugin binaries in CI before relying on them"],"tags":["plugin","exec","stderr"],"backgroundTag":"plugin-execution-failed","analyzedSha":"0d69dca6f532ceaeacd615d35d1eaa41a238ffdb","analyzedAt":"2026-08-31T12:19:21.182Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}