{"record":{"id":"489c13ae5bd0a5b5","repo":"hashicorp/nomad","slug":"v","errorCode":null,"errorMessage":"%v","messagePattern":"%v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command/operator_debug.go","lineNumber":1735,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tdefer jsonFh.Close()\n\n\tjson.NewEncoder(jsonFh).Encode(c.manifest)\n\n\t// Write the HTML\n\tpath = filepath.Join(c.collectDir, \"index.html\")\n\thtmlFh, err := os.Create(path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer htmlFh.Close()\n\n\thead, _ := template.New(\"head\").Parse(\"<html><head><title>{{.}}</title></head>\\n<body><h1>{{.}}</h1>\\n<ul>\")\n\tline, _ := template.New(\"line\").Parse(\"<li><a href=\\\"{{.}}\\\">{{.}}</a></li>\\n\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"%v\", err)\n\t}\n\ttail := \"</ul></body></html>\\n\"\n\n\thead.Execute(htmlFh, c.timestamp)\n\tfor _, f := range c.manifest {\n\t\tline.Execute(htmlFh, f)\n\t}\n\thtmlFh.WriteString(tail)\n\n\treturn nil\n}\n\n// trap captures signals, and closes stopCh\nfunc (c *OperatorDebugCommand) trap() {\n\tsigCh := make(chan os.Signal, 1)\n\tsignal.Notify(sigCh,\n\t\tsyscall.SIGHUP,\n\t\tsyscall.SIGINT,","sourceCodeStart":1717,"sourceCodeEnd":1753,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/command/operator_debug.go#L1717-L1753","documentation":"While generating the HTML index for the debug bundle, template parsing errors are silently discarded with `head, _ :=` / `line, _ :=`, and then a stale `err` (from an earlier statement, e.g. creating the HTML file) is re-checked and wrapped with `%v`. The template parses shown always succeed, so this error surfaces only when the earlier file-creation step failed, and the message loses the error's type (unwrapped via %v).","triggerScenarios":"The `err` variable left over from creating/opening the HTML output file (htmlFh) is non-nil when control reaches the check after the template.Parse calls, producing fmt.Errorf(\"%v\", err).","commonSituations":"`nomad operator debug` cannot create its HTML index file because the output directory is missing, unwritable, or the disk is full; the real cause is hidden because the error is stringified, not wrapped.","solutions":["Look at the stringified message body for the underlying OS error (path, permission, or ENOSPC)","Ensure the -output directory for the debug bundle exists and is writable","Free disk space if the message indicates a full filesystem","Fix the code to check err immediately after creating htmlFh and wrap with %w instead of %v to preserve the cause"],"exampleFix":"// before\nhead, _ := template.New(\"head\").Parse(...)\nline, _ := template.New(\"line\").Parse(...)\nif err != nil {\n    return fmt.Errorf(\"%v\", err)\n}\n// after\nfh, err := os.Create(...)\nif err != nil {\n    return fmt.Errorf(\"failed to create html file: %w\", err)\n}\nhead, err := template.New(\"head\").Parse(...)\nif err != nil {\n    return fmt.Errorf(\"failed to parse head template: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// before generating the bundle index, verify the html file was created\nfh, err := os.Create(htmlPath)\nif err != nil {\n    return fmt.Errorf(\"create html index: %w\", err)\n}\n// and validate templates eagerly\nif _, err := template.New(\"head\").Parse(headTmpl); err != nil {\n    return fmt.Errorf(\"bad head template: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := generateIndex(htmlFh, c); err != nil {\n    log.Printf(\"debug bundle index generation failed: %v\", err)\n    // inspect inner OS error for the real filesystem cause\n}","preventionTips":["Never discard template parse errors with `_`; check them immediately","Check err right after each os.Create/Write step, not several statements later","Wrap errors with %w so callers can errors.Is/As the cause","Ensure the debug output directory is writable before starting collection"],"tags":["templates","io","debug-bundle"],"backgroundTag":"file-write-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}