{"record":{"id":"39e702e61a26ba11","repo":"wavetermdev/waveterm","slug":"writing-file-w","errorCode":null,"errorMessage":"writing file: %w","messagePattern":"writing file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file.go","lineNumber":261,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tfileData := wshrpc.FileData{\n\t\tInfo: &wshrpc.FileInfo{\n\t\t\tPath: path}}\n\n\tlimitReader := io.LimitReader(WrappedStdin, MaxFileSize+1)\n\tdata, err := io.ReadAll(limitReader)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"reading input: %w\", err)\n\t}\n\tif len(data) > MaxFileSize {\n\t\treturn fmt.Errorf(\"input exceeds maximum file size of %d bytes\", MaxFileSize)\n\t}\n\tfileData.Data64 = base64.StdEncoding.EncodeToString(data)\n\terr = wshclient.FileWriteCommand(RpcClient, fileData, &wshrpc.RpcOpts{Timeout: fileTimeout})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"writing file: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc fileAppendRun(cmd *cobra.Command, args []string) error {\n\tpath, err := fixRelativePaths(args[0])\n\tif err != nil {\n\t\treturn err\n\t}\n\tfileData := wshrpc.FileData{\n\t\tInfo: &wshrpc.FileInfo{\n\t\t\tPath: path}}\n\n\tinfo, err := ensureFile(fileData)\n\tif err != nil {\n\t\treturn err\n\t}","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file.go#L243-L279","documentation":"wsh file write wraps any error returned by the FileWriteCommand RPC (which streams the base64-encoded file data to the Wave block/server) with 'writing file: %w'. It indicates the remote write failed after the client already validated the 10MB MaxFileSize limit. Common causes are RPC timeouts (fileTimeout), connection loss to the block, or a server-side write failure (permissions, disk full, invalid path).","triggerScenarios":"Running 'wsh file write [block] <file>' where the underlying wshclient.FileWriteCommand returns an error: RPC timeout, no router/connection to the target block, remote path not writable, or disk full on the remote.","commonSituations":"Writing a large file (~10MB, near the limit) so the RPC hits fileTimeout; targeting a block that has closed or disconnected; writing to a path without permissions on the remote machine.","solutions":["Check connectivity to the target block/tab and rerun the command","Increase --timeout (fileTimeout) if the file is large or the connection is slow","Verify the destination path exists and is writable on the remote","Confirm the file is under the 10MB MaxFileSize before writing"],"exampleFix":"// before\nif err != nil {\n    return fmt.Errorf(\"writing file: %w\", err)\n}\n// after\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        return fmt.Errorf(\"writing file: rpc timed out, try a longer --timeout: %w\", err)\n    }\n    return fmt.Errorf(\"writing file: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"info, err := os.Stat(localPath)\nif err != nil { return err }\nif info.Size() >= 10*1024*1024 {\n    return fmt.Errorf(\"%s exceeds the 10MB write limit\", localPath)\n}","typeGuard":"func isTimeoutErr(err error) bool {\n    return errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)\n}","tryCatchPattern":"err := fileWriteRun(cmd, args)\nvar rpcErr *wshrpc.RpcError\nif errors.As(err, &rpcErr) {\n    // handle RPC-level failure (retry with longer timeout)\n} else if err != nil {\n    // surface wrapped cause: fmt.Sprintf(\"%+v\", errors.Unwrap(err))\n}","preventionTips":["Check file size against the 10MB cap before invoking wsh file write","Use a generous --timeout for large files or slow links","Confirm the target block is alive before transferring","Pre-create/verify the remote path is writable"],"tags":["rpc","file-write","network","timeout"],"backgroundTag":"rpc-call-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}