{"record":{"id":"52e36ec6fe735318","repo":"chenhg5/cc-connect","slug":"pico2wave-create-temp-file-w","errorCode":null,"errorMessage":"pico2wave: create temp file: %w","messagePattern":"pico2wave: create temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":621,"sourceCode":"\t}\n\treturn &PicoTTS{\n\t\tPath:  path,\n\t\tVoice: voice,\n\t}\n}\n\n// Synthesize uses pico2wave to convert text to WAV audio bytes.\n// pico2wave produces much better quality than espeak.\nfunc (p *PicoTTS) Synthesize(ctx context.Context, text string, opts TTSSynthesisOpts) ([]byte, string, error) {\n\tvoice := opts.Voice\n\tif voice == \"\" {\n\t\tvoice = p.Voice\n\t}\n\n\t// Create secure temp file for pico2wave output\n\ttmpFile, err := os.CreateTemp(\"\", \"pico_tts_*.wav\")\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"pico2wave: create temp file: %w\", err)\n\t}\n\ttmpPath := tmpFile.Name()\n\ttmpFile.Close()\n\tdefer os.Remove(tmpPath)\n\n\t// Build pico2wave command\n\t// --lang: language code (zh-CN for Chinese, en-US for English)\n\t// --wave: output WAV file path\n\targs := []string{\n\t\t\"--lang=\" + voice,\n\t\t\"--wave=\" + tmpPath,\n\t\ttext,\n\t}\n\n\t// Execute pico2wave command\n\tcmd := exec.CommandContext(ctx, p.Path, args...)\n\toutput, err := cmd.CombinedOutput()\n\tif err != nil {","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L603-L639","documentation":"PicoTTS.Synthesize first creates a temporary WAV file (os.CreateTemp with pattern pico_tts_*.wav) that pico2wave will write into; this error wraps the failure of that temp-file creation. It almost always indicates a filesystem-level problem: the OS temp directory does not exist, is full, or the process lacks write permission to it — often because TMPDIR/TEMP points somewhere unwritable.","triggerScenarios":"Calling Synthesize via PicoTTS when os.CreateTemp(\"\", ...) fails: TMPDIR set to a nonexistent or read-only directory, /tmp full or mounted read-only, disk quota exhausted, or running in a sandbox with no writable temp dir.","commonSituations":"Docker/Kubernetes containers with a read-only root filesystem and no tmpfs at /tmp; systemd services with PrivateTmp or restrictive ReadWritePaths; TMPDIR exported to a deleted directory; disk-full conditions on long-running hosts.","solutions":["Check the temp directory: `echo $TMPDIR`, `df -h /tmp`, `touch /tmp/x` to confirm writability; fix TMPDIR or free space.","For systemd deployments, add the temp dir to ReadWritePaths= or adjust PrivateTmp restrictions.","Mount a writable tmpfs at /tmp in the container (e.g. docker run --tmpfs /tmp) or make the filesystem writable.","As a fallback, pass an application-configured writable directory to os.CreateTemp instead of the OS default."],"exampleFix":"// before\n# systemd unit\nReadWritePaths=/var/lib/cc-connect   # /tmp not writable\n// after\n# systemd unit\nReadWritePaths=/var/lib/cc-connect /tmp\n# or in code: honor a configurable temp dir\n// dir := configuredTempDir (defaults to os.TempDir())\ntmpFile, err := os.CreateTemp(dir, \"pico_tts_*.wav\")","handlingStrategy":"validation","validationCode":"// Go: verify a writable temp dir before synthesis\nprobe, err := os.CreateTemp(os.TempDir(), \"pico_probe_*.tmp\")\nif err != nil {\n\treturn fmt.Errorf(\"no writable temp dir: %w\", err)\n}\nname := probe.Name()\nprobe.Close()\nos.Remove(name)","typeGuard":null,"tryCatchPattern":"audio, format, err := pico.Synthesize(ctx, text, opts)\nif err != nil {\n\tif strings.Contains(err.Error(), \"create temp file\") {\n\t\t// check TMPDIR, disk space, permissions before retrying\n\t\tlog.Printf(\"temp dir unwritable: TMPDIR=%s err=%v\", os.TempDir(), err)\n\t}\n\treturn err\n}","preventionTips":["Ensure TMPDIR/TEMP points to an existing writable directory in every deployment (containers, systemd units).","Mount a tmpfs at /tmp in containers; include /tmp in ReadWritePaths for systemd sandboxes.","Monitor disk space on hosts running local TTS engines.","Probe temp-dir writability at startup rather than at first request."],"tags":["tts","pico2wave","filesystem","temp-file"],"backgroundTag":"file-write-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}