{"record":{"id":"fac4b6b37cdca8d7","repo":"wavetermdev/waveterm","slug":"cannot-create-directory-q-w","errorCode":null,"errorMessage":"cannot create directory %q: %w","messagePattern":"cannot create directory %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshrpc/wshremote/wshremote_file.go","lineNumber":424,"sourceCode":"\t\t\t\tDir:           computeDirPart(cleanedPath),\n\t\t\t\tName:          filepath.Base(cleanedPath),\n\t\t\t\tStatError:     err.Error(),\n\t\t\t\tSupportsMkdir: true,\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\trtn[path] = *fileInfo\n\t}\n\treturn rtn, nil\n}\n\nfunc (impl *ServerImpl) RemoteFileTouchCommand(ctx context.Context, path string) error {\n\tcleanedPath := filepath.Clean(wavebase.ExpandHomeDirSafe(path))\n\tif _, err := os.Stat(cleanedPath); err == nil {\n\t\treturn fmt.Errorf(\"file %q already exists\", path)\n\t}\n\tif err := os.MkdirAll(filepath.Dir(cleanedPath), 0755); err != nil {\n\t\treturn fmt.Errorf(\"cannot create directory %q: %w\", filepath.Dir(cleanedPath), err)\n\t}\n\tif err := os.WriteFile(cleanedPath, []byte{}, 0644); err != nil {\n\t\treturn fmt.Errorf(\"cannot create file %q: %w\", cleanedPath, err)\n\t}\n\treturn nil\n}\n\nfunc (impl *ServerImpl) RemoteFileMoveCommand(ctx context.Context, data wshrpc.CommandFileCopyData) error {\n\tdestUri := data.DestUri\n\tsrcUri := data.SrcUri\n\n\tdestConn, err := connparse.ParseURIAndReplaceCurrentHost(ctx, destUri)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"cannot parse destination URI %q: %w\", srcUri, err)\n\t}\n\tdestPathCleaned := filepath.Clean(wavebase.ExpandHomeDirSafe(destConn.Path))\n\t_, err = os.Stat(destPathCleaned)\n\tif err == nil {","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshrpc/wshremote/wshremote_file.go#L406-L442","documentation":"RemoteFileTouchCommand wraps os.MkdirAll failure for the parent directory of the target file (created with 0755 before writing the file). Cause is permission denied, a path component being a file, or I/O errors.","triggerScenarios":"Touching a path whose parent directory cannot be created: ancestor is an existing regular file, write permission missing, or read-only filesystem.","commonSituations":"Creating files under read-only mounts; path like /home/user/file.txt/sub/deep where file.txt is a file; permission-restricted home directories.","solutions":["Read the wrapped error to find which directory component failed.","Ensure no ancestor path component is an existing file.","Check write permission on the nearest existing ancestor.","Create parent directories manually with correct permissions if 0755 is unsuitable."],"exampleFix":"// before\nwshclient.RemoteFileTouchCommand(ctx, \"/srv/data/app/log.txt\", nil)\n// after\nif _, err := wshclient.RemoteFileInfoCommand(ctx, \"/srv/data/app\", nil); err != nil {\n    return fmt.Errorf(\"parent dir unavailable: %w\", err)\n}\nwshclient.RemoteFileTouchCommand(ctx, \"/srv/data/app/log.txt\", nil)","handlingStrategy":"validation","validationCode":"parent := filepath.Dir(path)\ninfo, err := wshclient.RemoteFileInfoCommand(ctx, parent, nil)\nif err == nil && !info.Dir { return fmt.Errorf(\"%s is a file, not a dir\", parent) }","typeGuard":null,"tryCatchPattern":"err := wshclient.RemoteFileTouchCommand(ctx, path, nil)\nif err != nil && strings.Contains(err.Error(), \"cannot create directory\") {\n    // inspect wrapped errno: EACCES / ENOTDIR\n}","preventionTips":["Ensure no ancestor component is a regular file","Verify write permission on the nearest existing ancestor","Avoid read-only mounts for file creation"],"tags":["filesystem","mkdir","permissions","path"],"backgroundTag":"mkdir-permission-denied","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}