{"record":{"id":"24ec8ce01b33741e","repo":"wavetermdev/waveterm","slug":"failed-to-write-s-w","errorCode":null,"errorMessage":"failed to write %s: %w","messagePattern":"failed to write (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/waveappstore/waveappstore.go","lineNumber":798,"sourceCode":"\t}\n\n\tappDir, err := GetAppDir(appId)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif bindings == nil {\n\t\tbindings = make(map[string]string)\n\t}\n\n\tdata, err := json.MarshalIndent(bindings, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal bindings: %w\", err)\n\t}\n\n\tbindingsPath := filepath.Join(appDir, SecretBindingsFileName)\n\tif err := os.WriteFile(bindingsPath, data, 0644); err != nil {\n\t\treturn fmt.Errorf(\"failed to write %s: %w\", SecretBindingsFileName, err)\n\t}\n\n\treturn nil\n}\n\nfunc BuildAppSecretEnv(appId string, manifest *wshrpc.AppManifest, bindings map[string]string) (map[string]string, error) {\n\tif manifest == nil {\n\t\treturn make(map[string]string), nil\n\t}\n\n\tif bindings == nil {\n\t\tbindings = make(map[string]string)\n\t}\n\n\tsecretEnv := make(map[string]string)\n\n\tfor secretName, secretMeta := range manifest.Secrets {\n\t\tboundSecretName, hasBinding := bindings[secretName]","sourceCodeStart":780,"sourceCodeEnd":816,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/waveappstore/waveappstore.go#L780-L816","documentation":"After marshaling, WriteAppSecretBindings writes the JSON to SecretBindingsFileName inside the app's directory with os.WriteFile (mode 0644). If the file cannot be written, the OS error is wrapped as 'failed to write <file>: %w'. This indicates a filesystem-level problem, not a data problem.","triggerScenarios":"os.WriteFile fails because the app directory does not exist, the process lacks write permission on the file or directory, the disk is full, the path is read-only, or on Windows the file is locked by another process.","commonSituations":"App store directory was deleted or never created (GetAppDir succeeded but dir was removed concurrently); running with a different user/permissions than the one that owns ~/.waveterm; read-only home mount; antivirus/indexer holding the file on Windows; ENOSPC on a full disk.","solutions":["Read the wrapped %w error (EACCES/ENOENT/ENOSPC/ELOCKED) to identify the exact OS cause","Ensure the app directory exists (recreate via the install flow or os.MkdirAll) before writing","Fix permissions on the app store directory or run as the owning user","Free disk space if the error indicates ENOSPC","Retry if the file was transiently locked by another process"],"exampleFix":"// before\nerr := waveappstore.WriteAppSecretBindings(appId, bindings) // ENOENT\n// after\nappDir, _ := waveappstore.GetAppDir(appId)\nif err := os.MkdirAll(appDir, 0755); err != nil {\n    return err\n}\nerr = waveappstore.WriteAppSecretBindings(appId, bindings)","handlingStrategy":"try-catch","validationCode":"appDir, err := waveappstore.GetAppDir(appId)\nif err != nil { return err }\nif info, err := os.Stat(appDir); err != nil || !info.IsDir() {\n    if mkErr := os.MkdirAll(appDir, 0755); mkErr != nil { return mkErr }\n}\nif err := unix.Access(appDir, unix.W_OK); err != nil { return fmt.Errorf(\"app dir not writable: %w\", err) }","typeGuard":"func dirWritable(path string) bool {\n    info, err := os.Stat(path)\n    return err == nil && info.IsDir() && unix.Access(path, unix.W_OK) == nil\n}","tryCatchPattern":"if err := waveappstore.WriteAppSecretBindings(appId, bindings); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Printf(\"write failed at %s: %v\", perr.Path, perr.Err)\n    }\n    return err\n}","preventionTips":["Ensure the app directory exists before writing","Run Wave as the user that owns the data directory","Monitor disk space; check AV/indexer interference on Windows"],"tags":["go","filesystem","io"],"backgroundTag":"file-write-permission-denied","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}