{"record":{"id":"b9d7b20aa9488952","repo":"kopia/kopia","slug":"error-writing-template-to-file","errorCode":null,"errorMessage":"error writing template to file","messagePattern":"error writing template to file","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command_notification_template_show.go","lineNumber":64,"sourceCode":"\t} else {\n\t\tvar found bool\n\n\t\ttext, found, err = notifytemplate.GetTemplate(ctx, rep, c.templateName)\n\t\tif !found {\n\t\t\ttext, err = notifytemplate.GetEmbeddedTemplate(c.templateName)\n\t\t}\n\t}\n\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"error listing templates\")\n\t}\n\n\tif c.htmlOutput {\n\t\ttf := filepath.Join(os.TempDir(), \"kopia-template-preview.html\")\n\n\t\t//nolint:gosec,mnd\n\t\tif err := os.WriteFile(tf, []byte(text), 0o644); err != nil {\n\t\t\treturn errors.Wrap(err, \"error writing template to file\")\n\t\t}\n\n\t\topen.Run(tf) //nolint:errcheck\n\t}\n\n\tc.out.printStdout(\"%v\\n\", strings.TrimRight(text, \"\\n\"))\n\n\treturn nil\n}\n","sourceCodeStart":46,"sourceCodeEnd":74,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/command_notification_template_show.go#L46-L74","documentation":"When --html-output is used, notification-template show writes the rendered template text to a temp file (kopia-template-preview.html) so it can be opened in a browser, and wraps any os.WriteFile failure as \"error writing template to file\". It is a filesystem write failure, not a template problem.","triggerScenarios":"os.WriteFile(tf, []byte(text), 0o644) fails while writing to os.TempDir(): read-only temp directory, full disk, TMPDIR pointing to a non-writable or nonexistent path, or permission restrictions.","commonSituations":"TMPDIR set to a path the user cannot write; disk full; running in a hardened sandbox/container with /tmp mounted noexec or read-only; quota exceeded.","solutions":["Fix TMPDIR / ensure the temp directory exists and is writable by the current user.","Free disk space if the filesystem is full.","Run without --html-output to print the template to stdout instead.","Check permissions/quota on the temp filesystem."],"exampleFix":"// before\nTMPDIR=/nonexistent kopia notification template show email-html --html-output\n// after\nexport TMPDIR=/tmp\nkopia notification template show email-html --html-output","handlingStrategy":"fallback","validationCode":"if fi, err := os.Stat(os.TempDir()); err != nil || !fi.IsDir() { return errors.New(\"temp dir unavailable; skip --html-output\") }","typeGuard":null,"tryCatchPattern":"if err := os.WriteFile(tf, []byte(text), 0o644); err != nil {\n    log.Warnf(\"html preview unavailable (%v); printing to stdout\", err)\n    fallbackToStdout(text)\n    return nil\n}","preventionTips":["Keep TMPDIR pointing at a writable directory.","Monitor disk space on the temp filesystem.","Omit --html-output in sandboxed environments."],"tags":["cli","filesystem","temp-file","write"],"backgroundTag":"file-write-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}